faqts : Computers : Programming : Languages : JavaScript : Forms : SELECT

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

11 of 11 people (100%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

I want to populate a select box with number of days of the month selected. How can I do it?

Feb 7th, 2002 03:31
Don Philippo,


try:

<html>
 <head>
  <script language="JavaScript">
   function fnPopulateDateSelect()
   {
    objSelMonths=document.forms.frmSelectDate.selMonths;
    objSelDates=document.forms.frmSelectDate.selDates;
    objSelDates.options.length=0;
    intNumberOfDays=objSelMonths.options
[objSelMonths.selectedIndex].value;

    for (intCounter=0;intCounter<intNumberOfDays;intCounter++)
    {
     document.forms.frmSelectDate.selDates[intCounter] = new Option
(intCounter+1,intCounter+1,false,false);
    }
    objSelDates.focus();
   }
  </script>
 </head>
 <body onload="fnPopulateDateSelect()">
  <form name = "frmSelectDate">
   <select name="selMonths" onchange="fnPopulateDateSelect()">
    <option selected value="31">january</option>
    <option value="29">february</option>
    <option value="31">march</option>
    <option value="30">april</option>
    <option value="31">may</option>
    <option value="30">june</option>
    <option value="31">july</option>
    <option value="31">august</option>
    <option value="30">september</option>
    <option value="31">october</option>
    <option value="30">november</option>
    <option value="31">december</option>
   </select>
   <select name="selDates">
   </select>
  </form>
 </body>
</html>