Java Script load question.

Discussion in 'OT Technology' started by RaginBajin, Mar 6, 2003.

  1. RaginBajin

    RaginBajin Have you punched a donkey today?

    Joined:
    Dec 24, 2001
    Messages:
    8,740
    Likes Received:
    0
    Location:
    NoVA
    Alright so I've got my webpage built out and I've got a few date selectors that I submit through a form. The page default loads a year and a month, but no days of the month unless a change to the page takes place. That change runs the onChange command and executes a script pulling the days of the month from the machine. The problem I have is that when the page loads, there are no days defaulted. I need to have some sort of days defaulted when the page loads. I tried a few variations of onLoad, but with no success. Any help you can offer would be appreciated.

    <HTML>
    <HEAD>

    <!---Start Date JScript--->

    <SCRIPT LANGUAGE="JavaScript">

    <!-- Begin
    function populate(objForm,selectIndex) {
    timeA_start = new Date(objForm.start_year.options[objForm.start_year.selectedIndex].text, objForm.start_month.options[objForm.start_month.selectedInd
    ex].value,1);
    timeDifference_start = timeA_start - 86400000;
    timeB_start = new Date(timeDifference_start);
    var start_daysInMonth = timeB_start.getDate();
    for (var i = 0; i < objForm.start_day.length; i++) {
    objForm.start_day.options[0] = null;
    }
    for (var i = 0; i < start_daysInMonth; i++) {
    objForm.start_day.options = new Option(i+1);
    }
    document.f1.start_day.options[0].selected = true;
    }
    function getYears() {

    // You can easily customize what start_years can be used
    var start_years = new Array(1997,1998,1999,2000,2001,2002,2003,2004,2005)

    for (var i = 0; i < document.f1.start_year.length; i++) {
    document.f1.start_year.options[0] = null;
    }
    timeC_start = new Date();
    currYear_start = timeC_start.getFullYear();
    for (var i = 0; i < start_years.length; i++) {
    document.f1.start_year.options = new Option(start_years);
    }
    document.f1.start_year.options[2].selected=true;
    }
    window.onLoad = getYears;
    // End -->
    </script>

    <BODY
    BGCOLOR="#FFFFFF"
    TEXT="#000000"
    LINK="#0000FF"
    VLINK="#000080"
    ALINK="#FF0000"
    >


    <!---START DATE INPUT--->

    <FORM name=f1 METHOD="POST" ACTION="script.pl">

    <TABLE>
    <TR>
    <TD WIDTH="100%">
    <TABLE BORDER=6 CELLPADDING=6 BORDERCOLOR="#003366">
    <TR>
    <TD>
    <TABLE CELLPADDING=0 CELLSPACING=0>
    <TR VALIGN="center">
    <TD COLSPAN=10 ALIGN="center" BGCOLOR="#003366" STYLE="color: C0C09D">
    <H2><FONT FACE="arial">Title</FONT></H2>
    </TD>
    </TR>
    <TR>
    <TD>
    <FONT FACE="arial" SIZE=2><B>Start Date:</B></FONT>
    <BR>
    <FONT FACE="arial" SIZE=1 STYLE="color: FF0000">(Required)</FONT>
    <BR>

    <select name=start_year onChange="populate(this.form,this.form.start_month.selectedIndex);">
    <option value=1999>1999</option>
    <option value=2000>2000</option>
    <option value=2001>2001</option>
    <option value=2002>2002</option>
    <option selected value=2003>2003</option>
    </select>

    <SELECT NAME=start_month onChange="populate(this.form,this.selectedIndex);">
    <OPTION VALUE="01">January</OPTION>
    <OPTION SELECTED VALUE="02">February</OPTION SELECTED>
    <OPTION VALUE="03">March</OPTION>
    <OPTION VALUE="04">April</OPTION>
    <OPTION VALUE="05">May</OPTION>
    <OPTION VALUE="06">June</OPTION>
    <OPTION VALUE="07">July</OPTION>
    <OPTION VALUE="08">August</OPTION>
    <OPTION VALUE="09">September</OPTION>
    <OPTION VALUE="10">October</OPTION>
    <OPTION VALUE="11">November</OPTION>
    <OPTION VALUE="12">December</OPTION>
    </SELECT>

    <select name=start_day>
    <option> </option>
    <option> </option>
    <option> </option>
    <option> </option>
    <option> </option>
    <option> </option>
    </select>


    </TD>
    </TR>
     
  2. RaginBajin

    RaginBajin Have you punched a donkey today?

    Joined:
    Dec 24, 2001
    Messages:
    8,740
    Likes Received:
    0
    Location:
    NoVA

Share This Page