I have to disable all the select
menus in a div
and also set their value to null
.
I am using the following code to disable the select menus:
var div_contents =document.getElementById("div1");
var elements = div_contents.getElementsByTagName("select");
for (i=0; i<elements.length; i++) {
elements[i].disabled = true;
}
However, I am not able to set the value of the select tag to null
.
Also I don't have the null
option inside the select
tag:
<select id="test1" name="test1">
<option value="a">aa</option>
<option value="b">bb</option>
<option value="c">cc</option>
</select>
How can I set the value of a select
list to null
, given that I don't have the null
option?
If you want to show no selection, you should set its selectedIndex
to -1
.
elements[i].selectedIndex = -1;
You could try setting the element's value
property:
elements[i].value = '';
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