Topic: changing selected index in dropdown (Page 1 of 1) |
|
---|---|
Maniac (V) Mad Scientist From: Jacks raging bile duct.... |
posted 07-27-2009 17:53
Hi, |
Obsessive-Compulsive (I) Inmate From: Israel |
posted 09-07-2009 18:12
code: <% String p = (request.getParameter("p")==null)?"":request.getParameter("p"); %> <html> <script type="text/javascript"> function init(){ var s=document.getElementById("select"); for(var i=0;i<s.options.length;i++){ if(s.options[i].value=="<%=p%>"){ s.options[i].selected=true; break; } } } </script> <body onload="init()"> <select id="select"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> </body> </html> |
Nervous Wreck (II) Inmate From: United States |
posted 09-07-2009 19:29 |
Obsessive-Compulsive (I) Inmate From: Israel |
posted 09-08-2009 13:09
What if your values are not 1,2,3 but unkown strings, then you can't assume what option contains the value and you need to iterate them all... |
Lunatic (VI) Inmate From: under the bed |
posted 09-08-2009 18:26
If it's happening on page load, I would handle this server side personally... |
Obsessive-Compulsive (I) Inmate From: Israel |
posted 09-10-2009 09:35
I assume I would handle it server side as well but then it will be much harder to answer Boudga (depends on the language the server side is written) |
Nervous Wreck (II) Inmate From: |
posted 05-31-2011 11:04
Edit TP: spam removed
|