I have 2 select lists mySelect and mySelect2.
When one is selected if you click on the checkbox the other changes simultaneously.
Please check code below:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function displayResult() {
if(document.form1.billingtoo.checked == true) {
var x = document.getElementById("mySelect").selectedIndex;
// Set selected index for mySelect2
document.getElementById("mySelect2").selectedIndex = x;
}
}
</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>
…how do I disable (grey out) mySelect2 so that you cannot make any changes any changes once the values are in place?
thanks.
Not sure why your question is tagged “jQuery” when you’re not using any, but still:
Either way set the
disabledback tofalseto re-enable the control.Here’s one of many ways to rewrite your function with jQuery:
Demo: http://jsfiddle.net/nnnnnn/99TsC/