Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem passing parameters to a function

Status
Not open for further replies.

EdRev

Programmer
Aug 29, 2000
510
US
I coded these two functions that supplies the data on my calendar form. It works fine, but on random occassion I get an error message "months[...]is null or not an object" on line 8 of function drawCal(form), and sometimes I get an "undefined" on the "form.yearBox.value" line 13 of function drawCal(form). Am I missing anything on my function drawselection(form) that passes values to function drawCal(form)?

Any help will be greatly appreciated.....

Thanks!




function drawCal(form)
{
makeMonthArray()
var theYear=form.frmYear.value
var monthIndex=form.frmMonth.value + 1
if (monthIndex == 2)
months[monthIndex].length = getNumFebDays(theYear);
var firstMonthDay = months[monthIndex].getFirstMonthDay(theYear)
var numMonthDays = months[monthIndex].length
var monthName = months[monthIndex].name
form.monthBox.value = monthName
form.yearBox.value = form.frmYear.value
for (var i = 0; i < 42; i++)
if (i < firstMonthDay || i >= (numMonthDays + firstMonthDay))
form.dayBox.value = &quot;&quot;
else
form.dayBox.value = i - firstMonthDay + 1

}
function drawSelection(form)
{
for (var x = 0; x < 3; x++)
{if (form.frmYear[x].checked)
break;}
form.frmYear.value=x

if (x == 0)
form.frmYear.value=1999;
if (x == 1)
form.frmYear.value=2000;
if (x == 2)
form.frmYear.value=2001;

for (var i = 0; i < 12; i++)
{if (form.frmMonth.checked)
break;}
form.frmMonth.value=i
drawCal(form)
}




 
hi,
i don't see any problem with the code.. i think the problem may be -the function might be called before the page get loaded. I think i would be more better to help u if i could see from where the function is being called !
- ayyappan
 
Hello,

thanks for responding to my problem..Here's the code that generate my calendar table. As you can see I have an array of months and years radio button. This is how it (should) works - a user will click on the month button and depending on the year selected displays the month. When they click on the year, the month previously selected for that year is displayed. Again, the error messages are random (year and month combination).

thanks again.


var monthField = &quot;<input type=text name='monthBox' size=10>&quot;
var yearField = &quot;<input type=text name='yearBox' size=4>&quot;
var dayField = &quot;<input type=text name='dayBox' size=7>&quot;

var tableCode = &quot;<FORM NAME='calForm'<TABLE>&quot;
tableCode +=&quot;<tr><th><input type=radio name=frmMonth onClick='drawSelection(calForm)';>Jan</font></th>&quot;
tableCode +=&quot;<th><input type=radio name=frmMonth onClick='drawSelection(calForm)';>Feb</font></td>&quot;
tableCode +=&quot;<th><input type=radio name=frmMonth onClick='drawSelection(calForm)';>Mar</font></th>&quot;

.....rest table code

tableCode +=&quot;<th><input type=radio name=frmMonth onClick='drawSelection(calForm)';>Dec</b></font></th>&quot;
tableCode +=&quot;<tr><th colspan=12 align=center>&quot; + monthField + yearField + &quot;</th>&quot;

tableCode +=&quot;</table><TABLE background='blueps.gif'width=100%>&quot;
tableCode += &quot;<TR><TH><FONT COLOR='red'>Sun</FONT></TH>&quot; // do day headers
tableCode += &quot;<TH>Mon</TH><TH>Tue</TH><TH>Wed</TH><TH>Thu</TH><TH>Fri</TH>&quot;
tableCode += &quot;<TH><FONT COLOR='red'>Sat</FONT></TH></TR>&quot;
tableCode += &quot;<TR>&quot;
for (var i = 1; i < 43; i++)
{
if (i % 7 == 1 || i % 7 == 0)
tableCode += &quot;<TD width=14% height=35>&quot; + dayField + &quot;</TD>&quot;
else
tableCode += &quot;<TD>&quot; + dayField + &quot;</TD>&quot;
if (i == 42)
tableCode += &quot;</TR>&quot;
else if (i % 7 == 0)
tableCode += &quot;</TR><TR>&quot;
}
tableCode += &quot;</TABLE>&quot;
tableCode += &quot;<table><tr><td><input type=radio name=frmYear onClick='drawSelection(calForm)';>Last Year</input></td>&quot;
tableCode += &quot;<td><input type=radio name=frmYear checked onClick='drawSelection(calForm)';>Current Year</td>&quot;
tableCode += &quot;<td><input type=radio name=frmYear onClick='drawSelection(calForm)'; >Next Year</td>&quot;
tableCode += &quot;</TABLE><BR>&quot; //
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top