Rachel
Rachel

Reputation: 37

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){
       displaySelected =  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?

Upvotes: 0

Views: 945

Answers (2)

amal
amal

Reputation: 1369

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 

Upvotes: 1

Shadow Wizard
Shadow Wizard

Reputation: 66389

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.

Upvotes: 5

Related Questions