Latest Lists

how to select default option in html drop down list?

I have a drop down for date,month and year. I am using JavaScript loops to generate the code. Is there a way I can set the default value (selected="selected") for current date, month and year? I can use JavaScript to fetch current date, month and year from client but how do I use this data to set default values for the drop down?

Public Comments

  1. <html> <head> <script> setDate = function(d) { sDate.options[d-1].selected = true; }; </script> </head> <body> <select id=sDate> <option>1 <option>2 <option>3 <option>4 <option>5 </select> <span onclick="setDate(1)"> 1/MM/YYYY </span> <br> <span onclick="setDate(2)"> 2/MM/YYYY </span> <br> <span onclick="setDate(3)"> 3/MM/YYYY </span> <br> <span onclick="setDate(4)"> 4/MM/YYYY </span> <br> <span onclick="setDate(5)"> 5/MM/YYYY </span> <br> </body> </html>
Powered by Yahoo! Answers