0

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?

3
  • 2
    Apart from the concrete problem, why don't you just put it in a <form action="next.jsp"> and get the value in next.jsp by ${param.displayId}? Commented May 25, 2011 at 11:36
  • Maybe Ok for example project, but this is evil, follow @BalusC suggestion Commented May 25, 2011 at 11:38
  • 1
    To improve your chances to get better help, please Accept answers that solved your other questions. You have 6 questions already with pending answers. Commented May 25, 2011 at 11:38

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.