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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate: StartDate < EndDate

Validation

Validate: StartDate < EndDate

by  Rougy  Posted    (Edited  )
Works like a charm for me:

Here's the function:

function checkOut()
{
if (document.survey.txtSD.value == "Start Date") {
alert("Please enter a start date.");
return(false);
}
else {
if (document.survey.txtSD.value != "End Date") {
If (Date.parse(document.survey.txtSD.value) > Date.parse(document.survey.txtED.value)) {
alert("Invalid Date Range!\nStart Date cannot be after End Date!")
return false;
}
else {document.survey.action = "document.asp";}
}
else {document.survey.action = "document.asp";}
}
}

Here's the form:

<form name="survey" onSubmit="return checkOut(this.form)" method="post">
<input type="text" name="txtSD" id="StartDateID" value="Start Date" size="8" maxlength=10>
<input type="text" name="txtED" id="EndDateID" value="End Date" size="8" maxlength=10>
<input type="Submit" name="cmdSubmit" value="Submit">
</form>

Most of you should be able to cut and paste as you need. The presentation is poor (forgive me, it's hard to get the "}" parts to line up right.) This came in real handy for me. Hope it helps.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top