Dates in Select List

[Total: 0    Average: 0/5]

This creates a select list with the dates in it.

Body Code:

<FORM>
<SELECT NAME="dates" SIZE=1>
<SCRIPT LANGUAGE="JavaScript">

        today = new Date();
        thismonth = today.getMonth() + 1;
        thisyear = today.getYear();
        thisday = today.getDate();

        maxdays=31;//default

        // months with 30 days
        if (thismonth==4 || thismonth==6 || thismonth==9 || thismonth==11)
        {
                maxdays=30
        }

        // february, leap year
        if (thismonth==2)
        {
                // feb
                if ((thisyear/4)!=parseInt(thisyear/4))
                {
                        maxdays=28
                }
                else
                {
                        //leap year
                        maxdays=29
                }
        }

        thismonth = "" + thismonth
        if (thismonth.length == 1)
        {
                thismonth = "0" + thismonth;
        }

        for (var theday = 0; theday <= maxdays; theday++)
        {
                if (theday == 0)
                {
                        document.write ("<OPTION SELECTED> "+ thisday + "-" + thismonth + "-" + thisyear )
                        document.write ("<OPTION> ========")
                }
                else
                {
                        var thed = "" + theday
                        if (thed.length == 1)
                        {
                                thed = "0" + thed;
                        }
                        document.write ("<OPTION> " + thed + "-" + thismonth + "-" + thisyear)
                }
        }

</SCRIPT>
</SELECT>
</FORM>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *