By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,009 Members | 2,866 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,009 IT Pros & Developers. It's quick & easy.

Two drop-down list that used the same javascript function.

P: 2
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:



//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(WhichMonth, WhichYear)
var DaysInMonth = 31;
if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;
if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4)) DaysInMonth = 28;
if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4)) DaysInMonth = 29;
return DaysInMonth;

//function to change the available days in a months
function ChangeOptionDays(Which)
DaysObject = eval("document.Englishform." + Which + "Day");
MonthObject = eval("document.Englishform." + Which + "Month");
YearObject = eval("document.Englishform." + Which + "Year");

Month = MonthObject[MonthObject.selectedIndex].text;
Year = YearObject[YearObject.selectedIndex].text;

DaysForThisSelection = DaysInMonth(Month, Year);
CurrentDaysInSelection = DaysObject.length;
if (CurrentDaysInSelection > DaysForThisSelection)
for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)
DaysObject.options[DaysObject.options.length - 1] = null
if (DaysForThisSelection > CurrentDaysInSelection)
for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
NewOption = new Option(DaysObject.options.length + 1);
if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;

//function to set options to today
function SetToToday(Which)
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;


DaysObject[NowDay-1].selected = true;

//function to write option years minus x
function WriteYearOptions(YearsAhead)
line = "";
for (i=0; i<YearsAhead; i++)
line += "<OPTION>";
line += NowYear--;
return line;
// End -->

<body onLoad="SetToToday('FirstSelect');" >
<FORM NAME="Englishform" >
<!-- Contract date -->
<LABEL>Contract date</LABEL>
<SELECT name="FirstSelectMonth" onchange="ChangeOptionDays('FirstSelect')"><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="FirstSelectYear" onchange="ChangeOptionDays('FirstSelect')"> <SCRIPT language="JavaScript">
document.write(WriteYearOptions(10)); </SCRIPT></SELECT>

<!-- Date of birth -->
<LABEL>Date of issue</LABEL>
<SELECT name="FirstSelectMonth2" onchange="ChangeOptionDays('FirstSelect')"> <OPTION>Jan <OPTION>Feb <OPTION>Mar
<SELECT name="FirstSelectYear2" onchange="ChangeOptionDays('FirstSelect')"> <SCRIPT language="JavaScript">
document.write(WriteYearOptions(50)); </SCRIPT></SELECT>
<INPUT type=submit value=Submit name=Submit></DIV><br>
Jan 28 '08 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 15k+
P: 16,027
Welcome to TSDN!

What line does the error occur on?
Jan 28 '08 #2

P: 2
Thanks for replying !

Line 100. Plz help me through :(
Jan 28 '08 #3

Expert Mod 15k+
P: 16,027
The add() method of the select object has two arguments in standard-compliant browsers (i.e. browsers other than IE). See, for example, this link.
Jan 28 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.