[Javascript] FORM validation question

Neal, Craig CNeal at dthr.ab.ca
Tue Jan 28 10:45:41 CST 2003


 
I call a function called ValidateThis in my FORM which gets activated when
the Submit button is clicked: 

<FORM name="myform" method="POST" action="ProgramPlanning2.asp"
onSubmit="return ValidateThis(myform)"> 

The function is as follows:

function ValidateThis(formObj)
{
 var totalcount = formObj.NumberOfTables.value;
 var tableformat = formObj.TableFormat.value;
 var chairscount = formObj.NumberOfChairs.value;
 var chairsformat = formObj.ChairsFormat.value;
 var housekeepingrequest = formObj.HousekeepingRequest.checked;
 var hrd = formObj.HousekeepingRequestDate.value;
 var tvvcr = formObj.TVVCR.value;
 
 if (totalcount > 1 && tableformat == "Not applicable") {
  alert("You must select a table format when you have requested 2 or more
tables.");
  formObj.TableFormat.focus();
  return false;
 }
 
 else if (chairscount > 1 && chairsformat == "Not applicable") {
  alert("You must select a chairs format when you have requested 2 or more
chairs.");
  formObj.ChairsFormat.focus();
  return false;
 }
 else if ((housekeepingrequest && hrd == "") || (housekeepingrequest &&
(hrd.length != 10 || hrd.charAt(4) != '-' || hrd.charAt(7) != '-' ||
(hrd.charAt(5) != 1 && hrd.charAt(5) != 0)))) {
  alert("You have selected housekeeping request. Therefore you must include
a valid housekeeping request date in the format yyyy-mm-dd.");
  formObj.HousekeepingRequest.focus();
  return false;
 }
 else if (tvvcr < 0 || tvvcr > 2) {
  alert ("Invalid quantity of tv/vcr.");
  formObj.TVVCR.focus();
  return false;
 
 }
 else return true;
}

What I am realizing is that I have another 6 or 7 FORM fields that need to
be included in the data validation that are similar to tvvcr. I suppose for
each one I could add an additional line such as var videocams =
formObj.VideoCams.value; and add another else if section to test for the
quantity requested is no more than 2. However, any ideas how I can perhaps
do this in another function that is called from the main function please.
Thanks. 

 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20030128/bbc98f0c/attachment.htm>


More information about the Javascript mailing list