I have a problem with a html select object and its options in IE.
My html
<select id="Select1" onchange="closeMenu1(this.value)">
<option></option>
<option>1</option>
<optio开发者_运维技巧n>2</option>
And the javascript
function closeMenu1 (x) {
var show = document.getElementById("divID");
show.innerHTML = x;
}
Now, in every browser except the IEs the divID will show up the value which I selected in the select object. But IE doesn’t. Can somebody please tell me a way around that?
Thanks.
your options actually do not have values set, so you have two options
1) Set them
<select id="Select1" onchange="closeMenu1(this.value)">
<option value=''></option>
<option value='1'>1</option>
<option value='2'>2</option>
</select>
2)Use The selected index's text
Change your onchange event handler to as given below:
<select id="Select1" onchange="closeMenu1(this.options[this.selectedIndex].value)">
<option></option>
<option>1</option>
<option>2</option>
</select>
Try getting the value from inside your closeMenu1 function instead of trying to pass it in:
function closeMenu1() {
var val = document.getElementById("Select1").value;
var show = document.getElementById("divID");
show.innerHTML = val;
}
Then change the onchange
attribute to simply onchange="closeMenu1()"
.
精彩评论