Good morning all,
Please I need help in a form that I have designed to fill user information. This form needs two drop-down list about specific date, one about contract date, and the other about birth date. I am using java script function to display the dates, and use onload() function to set the drop-down list to the current date.
I following error used to appear (null or not an object)!! Can any one help me in that?
The code:
[HTML]<head>
<SCRIPT LANGUAGE="JavaS cript">
//set todays date
Now = new Date();
NowDay = Now.getDate();
NowMonth = Now.getMonth();
NowYear = Now.getYear();
if (NowYear < 2000) NowYear += 1900; //for Netscape
//function for returning how many days there are in a month including leap years
function DaysInMonth(Whi chMonth, WhichYear)
{
var DaysInMonth = 31;
if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;
if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(Whic hYear/4)) DaysInMonth = 28;
if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(Whic hYear/4)) DaysInMonth = 29;
return DaysInMonth;
}
//function to change the available days in a months
function ChangeOptionDay s(Which)
{
DaysObject = eval("document. Englishform." + Which + "Day");
MonthObject = eval("document. Englishform." + Which + "Month");
YearObject = eval("document. Englishform." + Which + "Year");
Month = MonthObject[MonthObject.sel ectedIndex].text;
Year = YearObject[YearObject.sele ctedIndex].text;
DaysForThisSele ction = DaysInMonth(Mon th, Year);
CurrentDaysInSe lection = DaysObject.leng th;
if (CurrentDaysInS election > DaysForThisSele ction)
{
for (i=0; i<(CurrentDaysI nSelection-DaysForThisSele ction); i++)
{
DaysObject.opti ons[DaysObject.opti ons.length - 1] = null
}
}
if (DaysForThisSel ection > CurrentDaysInSe lection)
{
for (i=0; i<(DaysForThisS election-CurrentDaysInSe lection); i++)
{
NewOption = new Option(DaysObje ct.options.leng th + 1);
DaysObject.add( NewOption);
}
}
if (DaysObject.sel ectedIndex < 0) DaysObject.sele ctedIndex == 0;
}
//function to set options to today
function SetToToday(Whic h)
{
DaysObject = eval("document. Englishform." + Which + "Day");
MonthObject = eval("document. Englishform." + Which + "Month");
YearObject = eval("document. Englishform." + Which + "Year");
YearObject[0].selected = true;
MonthObject[NowMonth].selected = true;
ChangeOptionDay s(Which);
DaysObject[NowDay-1].selected = true;
}
//function to write option years minus x
function WriteYearOption s(YearsAhead)
{
line = "";
for (i=0; i<YearsAhead; i++)
{
line += "<OPTION>";
line += NowYear--;
}
return line;
}
// End -->
</script>
</head>
<body onLoad="SetToTo day('FirstSelec t');" >
<FORM NAME="Englishfo rm" >
<!-- Contract date -->
<LABEL>Contra ct date</LABEL>
<SELECT name="FirstSele ctDay"> <OPTION>1 <OPTION>2 <OPTION>3 <OPTION>4 <OPTION>5 <OPTION>6 <OPTION>7 <OPTION>8 <OPTION>9 <OPTION>10 <OPTION>11 <OPTION>12 <OPTION>13 <OPTION>14 <OPTION>15 <OPTION>16
<OPTION>17 <OPTION>18 <OPTION>19 <OPTION>20 <OPTION>21 <OPTION>22 <OPTION>23 <OPTION>24 <OPTION>25 <OPTION>26 <OPTION>27 <OPTION>28 <OPTION>29 <OPTION>30 <OPTION>31 </SELECT>
<SELECT name="FirstSele ctMonth" onchange="Chang eOptionDays('Fi rstSelect')"><O PTION>Jan <OPTION>Feb <OPTION>Mar<OPT ION>Apr <OPTION>May <OPTION>Jun <OPTION>Jul <OPTION>Aug <OPTION>Sep <OPTION>Oct <OPTION>Nov <OPTION>Dec</SELECT>
<SELECT name="FirstSele ctYear" onchange="Chang eOptionDays('Fi rstSelect')"> <SCRIPT language="JavaS cript">
document.write( WriteYearOption s(10)); </SCRIPT></SELECT>
</DIV><br>
<!-- Date of birth -->
<LABEL>Date of issue</LABEL>
<DIV>
<SELECT name="FirstSele ctDay2"> <OPTION>1 <OPTION>2 <OPTION>3 <OPTION>4 <OPTION>5 <OPTION>6 <OPTION>7
<OPTION>8 <OPTION>9 <OPTION>10 <OPTION>11 <OPTION>12 <OPTION>13 <OPTION>14 <OPTION>15 <OPTION>16
<OPTION>17 <OPTION>18 <OPTION>19 <OPTION>20 <OPTION>21 <OPTION>22 <OPTION>23 <OPTION>24 <OPTION>25
<OPTION>26 <OPTION>27 <OPTION>28 <OPTION>29 <OPTION>30 <OPTION>31</SELECT>
<SELECT name="FirstSele ctMonth2" onchange="Chang eOptionDays('Fi rstSelect')"> <OPTION>Jan <OPTION>Feb <OPTION>Mar
<OPTION>Apr <OPTION>May <OPTION>Jun <OPTION>Jul <OPTION>Aug <OPTION>Sep <OPTION>Oct <OPTION>Nov <OPTION>Dec</SELECT>
<SELECT name="FirstSele ctYear2" onchange="Chang eOptionDays('Fi rstSelect')"> <SCRIPT language="JavaS cript">
document.write( WriteYearOption s(50)); </SCRIPT></SELECT>
</DIV><br>
<INPUT type=submit value=Submit name=Submit></DIV><br>
</FORM>
</div>
</body>
</html>[/HTML]
Please I need help in a form that I have designed to fill user information. This form needs two drop-down list about specific date, one about contract date, and the other about birth date. I am using java script function to display the dates, and use onload() function to set the drop-down list to the current date.
I following error used to appear (null or not an object)!! Can any one help me in that?
The code:
[HTML]<head>
<SCRIPT LANGUAGE="JavaS cript">
//set todays date
Now = new Date();
NowDay = Now.getDate();
NowMonth = Now.getMonth();
NowYear = Now.getYear();
if (NowYear < 2000) NowYear += 1900; //for Netscape
//function for returning how many days there are in a month including leap years
function DaysInMonth(Whi chMonth, WhichYear)
{
var DaysInMonth = 31;
if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;
if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(Whic hYear/4)) DaysInMonth = 28;
if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(Whic hYear/4)) DaysInMonth = 29;
return DaysInMonth;
}
//function to change the available days in a months
function ChangeOptionDay s(Which)
{
DaysObject = eval("document. Englishform." + Which + "Day");
MonthObject = eval("document. Englishform." + Which + "Month");
YearObject = eval("document. Englishform." + Which + "Year");
Month = MonthObject[MonthObject.sel ectedIndex].text;
Year = YearObject[YearObject.sele ctedIndex].text;
DaysForThisSele ction = DaysInMonth(Mon th, Year);
CurrentDaysInSe lection = DaysObject.leng th;
if (CurrentDaysInS election > DaysForThisSele ction)
{
for (i=0; i<(CurrentDaysI nSelection-DaysForThisSele ction); i++)
{
DaysObject.opti ons[DaysObject.opti ons.length - 1] = null
}
}
if (DaysForThisSel ection > CurrentDaysInSe lection)
{
for (i=0; i<(DaysForThisS election-CurrentDaysInSe lection); i++)
{
NewOption = new Option(DaysObje ct.options.leng th + 1);
DaysObject.add( NewOption);
}
}
if (DaysObject.sel ectedIndex < 0) DaysObject.sele ctedIndex == 0;
}
//function to set options to today
function SetToToday(Whic h)
{
DaysObject = eval("document. Englishform." + Which + "Day");
MonthObject = eval("document. Englishform." + Which + "Month");
YearObject = eval("document. Englishform." + Which + "Year");
YearObject[0].selected = true;
MonthObject[NowMonth].selected = true;
ChangeOptionDay s(Which);
DaysObject[NowDay-1].selected = true;
}
//function to write option years minus x
function WriteYearOption s(YearsAhead)
{
line = "";
for (i=0; i<YearsAhead; i++)
{
line += "<OPTION>";
line += NowYear--;
}
return line;
}
// End -->
</script>
</head>
<body onLoad="SetToTo day('FirstSelec t');" >
<FORM NAME="Englishfo rm" >
<!-- Contract date -->
<LABEL>Contra ct date</LABEL>
<SELECT name="FirstSele ctDay"> <OPTION>1 <OPTION>2 <OPTION>3 <OPTION>4 <OPTION>5 <OPTION>6 <OPTION>7 <OPTION>8 <OPTION>9 <OPTION>10 <OPTION>11 <OPTION>12 <OPTION>13 <OPTION>14 <OPTION>15 <OPTION>16
<OPTION>17 <OPTION>18 <OPTION>19 <OPTION>20 <OPTION>21 <OPTION>22 <OPTION>23 <OPTION>24 <OPTION>25 <OPTION>26 <OPTION>27 <OPTION>28 <OPTION>29 <OPTION>30 <OPTION>31 </SELECT>
<SELECT name="FirstSele ctMonth" onchange="Chang eOptionDays('Fi rstSelect')"><O PTION>Jan <OPTION>Feb <OPTION>Mar<OPT ION>Apr <OPTION>May <OPTION>Jun <OPTION>Jul <OPTION>Aug <OPTION>Sep <OPTION>Oct <OPTION>Nov <OPTION>Dec</SELECT>
<SELECT name="FirstSele ctYear" onchange="Chang eOptionDays('Fi rstSelect')"> <SCRIPT language="JavaS cript">
document.write( WriteYearOption s(10)); </SCRIPT></SELECT>
</DIV><br>
<!-- Date of birth -->
<LABEL>Date of issue</LABEL>
<DIV>
<SELECT name="FirstSele ctDay2"> <OPTION>1 <OPTION>2 <OPTION>3 <OPTION>4 <OPTION>5 <OPTION>6 <OPTION>7
<OPTION>8 <OPTION>9 <OPTION>10 <OPTION>11 <OPTION>12 <OPTION>13 <OPTION>14 <OPTION>15 <OPTION>16
<OPTION>17 <OPTION>18 <OPTION>19 <OPTION>20 <OPTION>21 <OPTION>22 <OPTION>23 <OPTION>24 <OPTION>25
<OPTION>26 <OPTION>27 <OPTION>28 <OPTION>29 <OPTION>30 <OPTION>31</SELECT>
<SELECT name="FirstSele ctMonth2" onchange="Chang eOptionDays('Fi rstSelect')"> <OPTION>Jan <OPTION>Feb <OPTION>Mar
<OPTION>Apr <OPTION>May <OPTION>Jun <OPTION>Jul <OPTION>Aug <OPTION>Sep <OPTION>Oct <OPTION>Nov <OPTION>Dec</SELECT>
<SELECT name="FirstSele ctYear2" onchange="Chang eOptionDays('Fi rstSelect')"> <SCRIPT language="JavaS cript">
document.write( WriteYearOption s(50)); </SCRIPT></SELECT>
</DIV><br>
<INPUT type=submit value=Submit name=Submit></DIV><br>
</FORM>
</div>
</body>
</html>[/HTML]
Comment