I am new to JavaScript with this being my first little app. I am working on this Calendar / Date Time Picker program. I seem to have entered a nightmare scenario where the app crashes and I cannot figure out what is doing the crashing. After some primitive sleuthing (ie successive document.writes to pinpoint the line which kills it, I seem to have narrowed in on a very innocent line of code:
month_start = new Date(this.Year, this.Month, 1);
this.Year and this.Month are attributes of the class/parent function. I checked them and they both contain valid values at this point. I placed a document.write before this line and it displays, but immediately following this line the program is not responsive and does not display a document.write.
Is there some kind of JavaScript 101 mistake I am making here?
This line is inside a pretty small function. The whole function looks like this:
function Display_Calendar_Week(x, month_days){
ds = '';
d=0;
//for the first day of the month, start at the appropriate day of the week
if(x==1)
{
//first date of current month and year
month_start = new Date(this.Year, this.Month, 1);
d = month_start.getDay();
}
for(j=0;j<7;j++)
{
if( (j<d) || (x > month_days))
{
ds +=('<div class="Calendar_Day_Square_Empty"></div>');
}
else
{
if((x==RightNow_Date) && (RightNow_Month==this.Month) && (RightNow_Year==this.Year))
{
ds +=('<div class="Calendar_Day_Square_Today" onClick="'+this.InstanceName+'.Select_Date(\''+ this.PageElement +'\', '+ this.Year +', '+ this.Month +', '+ x +');">' + x + '</div>');
}
else if((x==this.Selected_Date) && (this.Selected_Month==this.Month) && (this.Selected_Year==this.Year))
{
ds +=('<div class="Calendar_Day_Square_Selected" onClick="'+this.InstanceName+'.Select_Date(\''+ this.PageElement +'\', '+ this.Year +', '+ this.Month +', '+ x +');">' + x + '</div>');
}
else
ds +=('<div class="Calendar_Day_Square" onClick="'+this.InstanceName+'.Select_Date(\''+ this.PageElement +'\', '+ this.Year +', '+ this.Month +', '+ x +');">' + x + '</div>');
x++;
}
}
return [x, ds];
}