I have 2 comboboxes, "combo1" and "combo2",
If I select any value in combo1, I need that same value in combo2 as "selected" by JavaScript. What JavaScript code should be added to the HTML below to make it work?
<html>
<head>
<title>combo</title>
</head>
<body>
<form name="testForm" action="" method="post">
<select name="combo1">
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
</select><br /><br />
<select name="combo2">
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
</select>
</form>
</body>
</html>
<script type='text/javascript'>
window.onload = function() { BindEvent(); }
function BindEvent()
{
var elemToBind = document.getElementById ( "cmb1" );
elemToBind.onchange = function () { SetSel ( this ); }
}
function SetSel(elem)
{
var secondCombo = document.getElementById ( "cmb2" );
secondCombo.value = elem.value;
}
</script>
<body>
<select id="cmb1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<select id="cmb2">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</body>
onChange() can help
<select name="combo1" onChange="changeCombo2(...)"
>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With