Topic: changing selected index in dropdown |
|
---|---|
Author | Thread |
Maniac (V) Mad Scientist From: Jacks raging bile duct.... |
![]() ![]() ![]() ![]() Hi, |
Obsessive-Compulsive (I) Inmate From: Israel |
![]() ![]() ![]() ![]() 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 |
![]() ![]() ![]() ![]() |
Obsessive-Compulsive (I) Inmate From: Israel |
![]() ![]() ![]() ![]() 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 |
![]() ![]() ![]() ![]() If it's happening on page load, I would handle this server side personally... |
Obsessive-Compulsive (I) Inmate From: Israel |
![]() ![]() ![]() ![]() 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: |
![]() ![]() ![]() ![]() Edit TP: spam removed
|