Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] FORM validation question
- From: javascript@xxxxxxxxxx (Neal, Craig)
- Subject: [Javascript] FORM validation question
- Date: Tue, 28 Jan 2003 09:45:41 -0700
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C2C6EC.B1F28E00
Content-Type: text/plain; charset="iso-8859-1"
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.
------_=_NextPart_001_01C2C6EC.B1F28E00
Content-Type: text/html; charset="iso-8859-1"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 5.00.2919.6307" name=GENERATOR></HEAD>
<BODY>
<DIV> </DIV>
<DIV><FONT color=#800080><STRONG>
<DIV><FONT size=2><SPAN class=636470622-27012003><FONT face=Arial>I call a
function called ValidateThis in my FORM<SPAN class=062404416-28012003> which
gets activated when</SPAN><SPAN class=062404416-28012003> the Submit button is
clicked</SPAN>: <FONT color=#000000 size=1></FONT></FONT>
<P><FONT face=Arial><FONT color=#0000c0><FORM name=</FONT><FONT
color=#000000>"myform"</FONT><FONT color=#0000c0> method=</FONT><FONT
color=#000000>"POST"</FONT><FONT color=#0000c0> action=</FONT><FONT
color=#000000>"ProgramPlanning2.asp"</FONT><FONT color=#0000c0>
onSubmit=</FONT><FONT color=#000000>"return ValidateThis(myform)"</FONT><FONT
color=#0000c0>></FONT> </FONT></P>
<P><FONT face=Arial><SPAN class=636470622-27012003>The function is as
follows:</SPAN></FONT></P>
<P><FONT color=#0000c0 face=Arial><SPAN class=636470622-27012003>function
ValidateThis(formObj)<BR>{<BR> var totalcount =
formObj.NumberOfTables.value;<BR> var tableformat =
formObj.TableFormat.value;<BR> var chairscount =
formObj.NumberOfChairs.value;<BR> var chairsformat =
formObj.ChairsFormat.value;<BR> var housekeepingrequest =
formObj.HousekeepingRequest.checked;<BR> var hrd =
formObj.HousekeepingRequestDate.value;<BR> var tvvcr =
formObj.TVVCR.value;<BR> <BR> if (totalcount > 1 &&
tableformat == "Not applicable") {<BR> alert("You must select a table
format when you have requested 2 or more
tables.");<BR> formObj.TableFormat.focus();<BR> return
false;<BR> }<BR> <BR> else if (chairscount > 1 &&
chairsformat == "Not applicable") {<BR> alert("You must select a
chairs format when you have requested 2 or more
chairs.");<BR> formObj.ChairsFormat.focus();<BR> return
false;<BR> }<BR> else if ((housekeepingrequest && hrd == "")
|| (housekeepingrequest && (hrd.length != 10 || hrd.charAt(4) != '-' ||
hrd.charAt(7) != '-' || (hrd.charAt(5) != 1 && hrd.charAt(5) != 0))))
{<BR> alert("You have selected housekeeping request. Therefore you
must include a valid housekeeping request date in the format
yyyy-mm-dd.");<BR> formObj.HousekeepingRequest.focus();<BR> return
false;<BR> }<BR> else if (tvvcr < 0 || tvvcr > 2)
{<BR> alert ("Invalid quantity of
tv/vcr.");<BR> formObj.TVVCR.focus();<BR> return
false;<BR> <BR> }<BR> else return true;<BR>}</SPAN></FONT></P>
<P><FONT face=Arial><SPAN class=636470622-27012003>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. </SPAN></FONT></P></SPAN></FONT></DIV>
<DIV> </DIV></STRONG></FONT></DIV></BODY></HTML>
------_=_NextPart_001_01C2C6EC.B1F28E00--
- Prev by Date: [Javascript] onFocus getting error.
- Next by Date: [Javascript] CSS in JS function - where is the error?
- Previous by thread: [Javascript] Form validation question
- Next by thread: [Javascript] Java Script IE5+ on the Mac
- Index(es):