Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

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: Mon, 27 Jan 2003 15:14:29 -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_01C2C651.75D85E40
Content-Type: text/plain; 	charset="iso-8859-1"

I call a function called ValidateThis in my FORM: 

<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_01C2C651.75D85E40
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><FONT size=2><SPAN class=636470622-27012003><FONT face=Arial>I call a 
function called ValidateThis in my FORM: <FONT color=#000000 size=1></FONT>
<P></FONT><FONT face=Arial><FONT color=#0000c0>&lt;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>&gt;</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>&nbsp;var totalcount = 
formObj.NumberOfTables.value;<BR>&nbsp;var tableformat = 
formObj.TableFormat.value;<BR>&nbsp;var chairscount = 
formObj.NumberOfChairs.value;<BR>&nbsp;var chairsformat = 
formObj.ChairsFormat.value;<BR>&nbsp;var housekeepingrequest = 
formObj.HousekeepingRequest.checked;<BR>&nbsp;var hrd = 
formObj.HousekeepingRequestDate.value;<BR>&nbsp;var tvvcr = 
formObj.TVVCR.value;<BR>&nbsp;<BR>&nbsp;if (totalcount &gt; 1 &amp;&amp; 
tableformat == "Not applicable") {<BR>&nbsp;&nbsp;alert("You must select a table 
format when you have requested 2 or more 
tables.");<BR>&nbsp;&nbsp;formObj.TableFormat.focus();<BR>&nbsp;&nbsp;return 
false;<BR>&nbsp;}<BR>&nbsp;<BR>&nbsp;else if (chairscount &gt; 1 &amp;&amp; 
chairsformat == "Not applicable") {<BR>&nbsp;&nbsp;alert("You must select a 
chairs format when you have requested 2 or more 
chairs.");<BR>&nbsp;&nbsp;formObj.ChairsFormat.focus();<BR>&nbsp;&nbsp;return 
false;<BR>&nbsp;}<BR>&nbsp;else if ((housekeepingrequest &amp;&amp; hrd == "") 
|| (housekeepingrequest &amp;&amp; (hrd.length != 10 || hrd.charAt(4) != '-' || 
hrd.charAt(7) != '-' || (hrd.charAt(5) != 1 &amp;&amp; hrd.charAt(5) != 0)))) 
{<BR>&nbsp;&nbsp;alert("You have selected housekeeping request. Therefore you 
must include a valid housekeeping request date in the format 
yyyy-mm-dd.");<BR>&nbsp;&nbsp;formObj.HousekeepingRequest.focus();<BR>&nbsp;&nbsp;return 
false;<BR>&nbsp;}<BR>&nbsp;else if (tvvcr &lt; 0 || tvvcr &gt; 2) 
{<BR>&nbsp;&nbsp;alert ("Invalid quantity of 
tv/vcr.");<BR>&nbsp;&nbsp;formObj.TVVCR.focus();<BR>&nbsp;&nbsp;return 
false;<BR>&nbsp;<BR>&nbsp;}<BR>&nbsp;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>&nbsp;</DIV></BODY></HTML>

------_=_NextPart_001_01C2C651.75D85E40--