I have 2 select lists. There is a check box that when it is clicked it needs to feed the selected value selected into the other list.
I am up to the stage where I have managed to alert back the selected value in the first select list, my question is how to get the value in the second select list when the checkbox is clicked:
Please check code below of how far I have got:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function displayResult() {
if(document.form1.billingtoo.checked == true) {
var x = document.getElementById("mySelect").selectedIndex;
var y = document.getElementById("mySelect").options;
alert(y[x].text);
}
}
</script>
</head>
<body>
<form name="form1">
Select your favorite fruit:
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
<br>
<input type="checkbox" name="billingtoo" onclick="displayResult()">
<br>
Select your favorite fruit 2:
<select id="mySelect2">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
</form>
</body>
</html>
thanks.
Just set the selected index of the other select element.
jsFiddle Example
You could
getandsetthevaluepropertyof theobject, if you’re worried about the order of options being different.jsFiddle Example