Thursday, December 8, 2011

I have written a script to check the date a user selects in a form and it disables the submit button if a past?

date has been selected, and sends an alert saying "Please choose a future date." But it does not reset the submit button once they do select a future date. The form name is "Availability" the Year, Month, and Day drop downs are named the same thing "Year" "Month" "Day" respectively. Here is the script, could someone possibly tell me what to add to get it to make the submit button available once the user selects a future date?





%26lt;script%26gt;





var curDate =new Date();


var curYear = curDate.getFullYear();


var curMonth = curDate.getMonth()+1;


var curDay = curDate.getDate();


var actMonth = new Array(12);


actMonth[1]="January";


actMonth[2]="February";


actMonth[3]="March";


actMonth[4]="April";


actMonth[5]="May";


actMonth[6]="June";


actMonth[7]="July";


actMonth[8]="August";


actMonth[8]="September";


actMonth[10]="October";


actMonth[11]="November";


actMonth[12]="December";





function checkForm()


{


if (document.Availability.Year.value)


{


if (document.Availability.Year.value == curYear)


{


if (document.Availability.Month.value)


{


if (document.Availability.Month.value %26lt;= curMonth)


{


if (document.Availability.Day.value)


{


if (document.Availability.Day.value %26lt;= curDay)


{


alert("Please choose a future date");


document.Availability.submit.dis鈥?= "true";


} else {


document.Availability.submit.dis鈥?= "false";


}


}


}


}


}


}


}


%26lt;/script%26gt;|||Looks to me like you're re-enabling the button only if the last, innermost, test fails. You have to do it on all the other tests' failures as well. Or at least some of them.





In other words, if the curMonth test fails, the date is good and the button should be re-enabled.





Hope that helps.

No comments:

Post a Comment