Dropdown list not displaying in IE
I have drop down list with 5 items.
I want to send the selected item to next jsp page.
JavaScript code:
var display= document.getElementById('displayId');
var j;
var count =0;
for(j=0;j< display.options.length;j++){
if(display.options[j].selected){
displaySelec开发者_Go百科ted = display.options[j].value;
count++;
}
}
alert(displaySelected);
HTML code:
<SELECT NAME="displayId" id="displayId" style="width:300px;">
<option>Host</option>
<option>Host And Response Time</option>
<option>Host And User Count</option>
<option>User Count And Reponse Time</option>
<option>Host,UserCount And Response Time</option>
</SELECT>
This works in Fire fox but not in IE...Can anyone find the mistake?
You need to read the option text
as you don't have any value:
displaySelected = display.options[j].text;
Some browsers probably set the value to be the text when it's empty, IE is not among them.
Give values to your option tags .
Like
<option value="Host">Host</option>
rather than <option>Host</option>
.
And no need to find the selected value using a loop , you can always use
document.getElementById('displayId').value
精彩评论