...

View Full Version : Form Validation Help!!!



TTL
03-21-2004, 12:08 AM
Hi guys I'm a bit new to javascript and this forum. I'm having a real problem validating this forum that's due for my final. I need to have all areas of the forum validated but i can't figure out how! It used to work on 5 fields, but now it only works on 3 and I have no idea of how to fix it. So if anyone could please please help me it would mean the world to me and prevent me from failing my class lol Here's a url to the code and below i'll post the code itself too. http://www.indiexone.com/contactform.html

thanks in advance!



<script language="JavaScript" src="gen_validatorv2.js" type="text/javascript"></script>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

//-->
</script>
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT"/JAVASCRIPT">

<!-- hide script from old browsers

if (document.images) {
menu1 = new Image();
menu2 = new Image();
menu3 = new Image();
menu4 = new Image();
menu5 = new Image();
menu6 = new Image();
}
else {

menu1 = ""
menu2 = ""
menu3 = ""
menu4 = ""
menu5 = ""
menu6 = ""

}

// End hiding script from old browsers -->

</SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body {
background-color: #a5035b;
}
.style3 {font-family: Arial, Helvetica, sans-serif; font-size: 14px; }
.style5 {font-size: 10px}
.style6 {font-size: 11px}
.style7 {font-size: 11.5px}
.style9 {font-family: Arial, Helvetica, sans-serif; font-size: 13px; }
.style10 {
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
}
-->
</style></head>
<body>
<div id="Layer1" style="position:absolute; left:216px; top:377px; width:517px; height:284px; z-index:5">
<form action="" name="myform" >
<table width="367" height="389" border="0" cellpadding="2" cellspacing="2">
<tr>
<td align="right"><span class="style9">First Name</span></td>
<td width="256"><input name="FirstName" type="text" id="FirstName"></td>
</tr>
<tr>
<td align="right"><span class="style9">Last Name</span></td>
<td><input name="LastName" type="text" id="LastName"></td>
</tr>
<tr>
<td align="right"><span class="style9">Band Name </span></td>
<td><p>
<input name="bandname" type="text" id="bandname">
</p> </td>
</tr>
<tr>
<td align="right"><span class="style9">E-Mail</span></td>
<td><input name="Email" type="text" id="Email"></td>
</tr>
<tr>
<td align="right"><span class="style9">Genre</span></td>
<td> <span class="style5">
<INPUT TYPE="radio" NAME="radiobutton" onClick="radio_selection='pop'">
Pop
<INPUT TYPE="radio" NAME="radiobutton" onClick="radio_selection='rnb'">
R&amp;B
<INPUT TYPE="radio" NAME="radiobutton" onClick="radio_selection='other'">
Other</span></td>
</tr>
<tr>
<td align="right"><span class="style9">Age/Age Group </span></td>
<td><p>
<input name="age" type="text" id="age">
<span class="style5">(e.g: 20)</span></p></td>
</tr>
<tr>
<td align="right"><span class="style9">Todays Date </span></td>
<td><p>
<input name="date" type="text" id="date">
<span class="style5">(September 20,2004) <br>
</span></p> </td>
</tr>
<tr>
<td align="right"><span class="style9">Comments</span></td>
<td><textarea name="comments" cols="30" rows="5" id="comments"></textarea></td>
</tr>
<tr>
<td align="right"><span class="style9">State</span></td>
<td>
<p>
<select name="state" id="state">
<option value="">[choose yours]
<option value="008">Alabama
<option value="012">Alaska
<option value="016">Arizona
<option value="020">Arkansas
<option value="024">California
<option value="660">Colorado
<option value="010">Connecticut
<option value="028">Delaware
<option value="032">Florida
<option value="051">Georgia
<option value="533">Idaho
<option>Illinois
<option>Indiana
<option>Iowa
<option>Kansas
<option>Kentucky
<option>Louisiana
<option>Maine
<option>Maryland
<option>Massachusetts
<option>Michigan
<option>Minnesota
<option>Mississippi
<option>Missouri
<option>Montana
<option>Nebraska
<option>Nevada
<option>New Hampshire
<option>New Jersey
<option>New Mexico
<option>New York
<option>North Carolina
<option>North Dakota
<option>Ohio
<option>Oklahoma
<option>Oregon
<option>Pennsylvania
<option>Rhode Island
<option>South Carolina
<option>South Dakota
<option>Tennessee
<option>Texas
<option>Utah
<option>Vermont
<option>Virginia
<option>Washington
<option>West Virginia
<option>Wisconsin
<option>Wyoming
</select>
<br>
</p></td>
</tr>
<tr>
<td align="right"><span class="style9">
</span></td>
<td>
<p><span class="style10"><span class="style9">
<br>
<input type="checkbox" name="checkbox" value="checkbox">
</span>Join the Indie Xone mailing list.</span><br>
</p>
</td>
</tr>
<tr>
<td align="right"></td>
<td><input name="submit2" type="submit" value="Submit">
<INPUT name="reset" TYPE="reset" onClick="resetForm()" VALUE="Reset"> </td>
</tr>
</table>
</form>
</div>
<div id="Layer2" style="position:absolute; left:201px; top:22px; width:577px; height:120px; z-index:2">
<p><img src="images/logo.jpg" width="577" height="66"><a href="http://www.indiexone.com"><img src="images/homea.gif" alt="Home" name="menu1" width="53" height="27" border="0"
onmouseover="document.menu1.src='images/homeb.gif'"
onmouseout="document.menu1.src=menu1.src='images/homea.gif'"></a></a><img src="images/bar.gif" width="167" height="27"><img src="images/artists.gif" alt="Artists"name="menu2" width="95" height="27" border="0"
onmouseover="document.menu2.src='images/artistsa.gif'"
onmouseout="document.menu2.src=menu2.src='images/artists.gif'"></a><img src="images/join.gif" alt="Join"name="menu3" width="56" height="27" border="0"
onmouseover="document.menu3.src='images/joinb.gif'"
onmouseout="document.menu3.src=menu3.src='images/join.gif'"></a><img src="images/community.gif" alt="Community"name="menu4" width="90" height="27" border="0"
onmouseover="document.menu4.src='images/communitya.gif'"
onmouseout="document.menu4.src=menu4.src='images/community.gif'"></a><img src="images/faq.gif" alt="FAQ"name="menu5" width="53" height="27" border="0"
onmouseover="document.menu5.src='images/faqa.gif'"
onmouseout="document.menu5.src=menu5.src='images/faq.gif'"></a><img src="images/contact.gif" alt="Contact"name="menu6" width="63" height="27" border="0"
onmouseover="document.menu6.src='images/contacta.gif'"
onmouseout="document.menu6.src=menu6.src='images/contact.gif'"></a><img src="images/search.gif" width="577" height="34"></p>
</div>
<div id="Layer3" style="position:absolute; left:202px; top:149px; width:576px; height:411px; z-index:4"><img src="blank.gif" width="576" height="673"></div>
<div id="Layer4" style="position:absolute; left:217px; top:154px; width:541px; height:38px; z-index:6" class="style3">
<p><strong>Contact Indie Xone!<br>
</strong><br>
<span class="style7">If you're an independent artist who wants to submit your information/music for consideration please include the following information:</span></p>
<ul>
<li><span class="style5">Your or your Bands Name</span></li>
<li><span class="style5">Where you are located</span></li>
<li><span class="style5">Your music genre</span></li>
<li><span class="style5">A link to your song</span></li>
<li><span class="style5">A link to a picture of yourself or your band</span></li>
<li><span class="style5">Any other information you want to include</span></li>
</ul>
<p><span class="style6">Everyone else please just send in your question or comment. </span></p>
</div>
<script language="JavaScript" type="text/javascript">
//You should create the validator only after the definition of the HTML form
var frmvalidator = new Validator("myform");
frmvalidator.addValidation("FirstName","req","Please enter your First Name");
frmvalidator.addValidation("FirstName","maxlen=20",
"Max length for FirstName is 20");
frmvalidator.addValidation("FirstName","alpha");

frmvalidator.addValidation("LastName","req");
frmvalidator.addValidation("LastName","maxlen=20");

frmvalidator.addValidation("bandname","req","Please enter your Band Name");
frmvalidator.addValidation("bandname","maxlen=20");
frmvaldiator.addvalidation("bandname","alpha");

frmvalidator.addValidation("Email","maxlen=50");
frmvalidator.addValidation("Email","req", "Please enter your email address");
frmvalidator.addValidation("Email","email");

frmvalidator.addValidation("genre","maxlen=50");
frmvalidator.addValidation("genre","alpha");

frmvalidator.addValidation("age","maxlen=50");
frmvalidator.addValidation("age","numeric");
frmvalidator.addValidation("age","req");

frmvalidator.addValidation("date","maxlen=50");
frmvalidator.addValidation("date","alnum");
frmvalidator.addValidation("date","req");

frmvalidator.addValidation("comments","maxlen=50");
frmvalidator.addValidation("comments","req");
frmvalidator.addValidation("state","dontselect=0");

frmvalidator.addValidation("radiobutton","dontselect=0");

</script>
<div id="Layer2" style="position:absolute; left:563px; top:117px; width:216px; height:32px; z-index:2">
<FORM ACTION="search.php" METHOD="GET">
<INPUT TYPE="Text" NAME="query" SIZE="20">
<INPUT TYPE="Hidden" NAME="stpos" VALUE="0">
<INPUT name="Submit" TYPE="Submit" VALUE="Search">
</FORM>

Willy Duitt
03-21-2004, 12:55 AM
I do not see where you are even calling the Validator("myform") function. Therefore, I don't see how it could possibly validate three fields let alone five.

.....Willy

BTW: When you post code you need to use:

YOUR CODE HERE TAGS!
Please edit your post accordingly.

RadarBob
03-21-2004, 03:39 AM
I'm with W.D. I don't quite get all the what appears to be creating "validation objects."

I don't know about this "validator" thing because I don't see the code; it sounds to me like some all inclusive, ultra-generic form validation javascript object. OK, if that's code that was given to you and it works, then I don't know why there's a problem if you included all your fields. It doesn't make sense that some fields would validate and some wont - *if that formvalidator thingy works*.

Anyway here is my general approach to doing validation. This could help you avoid missing, leaving out, forgetting to validate on some field.

There are two places to do validation, first, right at the field like when you tab out of it you might want to check something ( "onblur" for example). The other place is when you SUBMIT the form. I use a combination of the two, It's a judgement call on which fields to validate "at" the field, but the bottom line is that you should always validate *everything* upon submit. You may think that redundant, but who knows what the user did on the form. It's just a safe bet.

Here is what your <form> tag would look like:


<form action="" name="myform" onsubmit='return validateForm(this);'>


The validateForm function must return either "true" or "false". If false, the form will not be submitted - that's the way HTML works. ValidateForm() is your "main routine" that will call all the other functions that validate the individual fields. BTW *every* validation function you write will pass "true" or "false". As you'll see this allows you to add more and more functions as needed and it will all work.

It's up to you to decide how many different functions you write: you could have just one that validates all required fields, checking for blanks. You could also write general functions to do generic checks, like checking if an input is a number for example; then call these generic functions from the validation function for the specific fields. And I very strongly advise you to write a separate function for every field that needs unique checking.

Be forewared: In general you will setting yourself up for many otherwise avoidable problems if you lump all your validation into one or two functions. It will be much harder to test and debug.

But regardless of how many functions you write, ALL functions follow this same pattern:
* create a boolean variable. Initialize it to true.
* do your validation check(s)
* set the variable to false if any validation fails
* return the boolean value.

Here's a notional "Main routine":


function validateForm(thisForm) {
var isValidForm = true;

if (!validateThisField(thisForm.ThisField)) {
isValidForm = false;
}

if(!validateThatField(thisForm.ThatField)) {
isValidform = false;
}

if (!validateRequiredFields(thisForm)) {
isValidForm = false;
}
return isValidForm;
}

Remember that our validation rouintes will always return a true or false. Thus when we put them inside of the IF(..) the "master validation flag" will be set to false when the called function returns "false". Otherwise we just leave the flag alone. So at the end of the main function, *no matter how many* functions we call, if any one returns false the master validation flag is false.

Here's what those "sub" functions might look like:


function validateRequiredfields(theForm) {
var allRequiredFieldsEntered = true;

if (theForm.thisField.value = "") {
allRequiredfieldsEntered = false;
}
// check other fields the same way

return allRequiredfieldsEntered;
}

function validateThisField (theField) {
var validField = true;

if (!isNumeric(theField)) { // check w/ home-made number-checker function
validField = false;
}

// other checks on this field as needed

return validField;
}

The beauty of this pattern for writing the code is
* the fundamental control logic is always the same - less room for errrors, or more likely to notice an error if you make one.

* You don't have to write your validation code all at once. It does not matter what order you write them in; what order you call them in from your main routine. Getting the validation for one field up and running is not dependant on any other.

*Depending on how you're supposed to use this "frmvalidator" thing, you might be able to apply these techniques there too.

Willy Duitt
03-21-2004, 05:22 AM
After visiting the site the script came from (http://www.javascript-coder.com). I seen the script
was using object constructors to perform the validation.

Anyways, I found the problems. You had a typo which would
have been easier to spot if the script indentation would have been
followed when you added your frmvalidator.addValidation objects.

There is a second problem with your naming the
radio group radiobuttons but later refering to genre.
I'll leave it to you to decide what you want to do with those.




<div id="Layer1" style="position:absolute; left:216px; top:377px; width:517px; height:284px; z-index:5">
<form action="" name="myform" >
<table width="367" height="389" border="0" cellpadding="2" cellspacing="2">
<tr>
<td align="right"><span class="style9">First Name</span></td>
<td width="256"><input name="FirstName" type="text" id="FirstName"></td>
</tr>
<tr>
<td align="right"><span class="style9">Last Name</span></td>
<td><input name="LastName" type="text" id="LastName"></td>
</tr>
<tr>
<td align="right"><span class="style9">Band Name </span></td>
<td><p>
<input name="bandname" type="text" id="bandname">
</p> </td>
</tr>
<tr>
<td align="right"><span class="style9">E-Mail</span></td>
<td><input name="Email" type="text" id="Email"></td>
</tr>
<tr>
<td align="right"><span class="style9">Genre</span></td>
<td> <span class="style5">
<INPUT TYPE="radio" NAME="genre" onClick="radio_selection='pop'">
Pop
<INPUT TYPE="radio" NAME="genre" onClick="radio_selection='rnb'">
R&B
<INPUT TYPE="radio" NAME="genre" onClick="radio_selection='other'">
Other</span></td>
</tr>
<tr>
<td align="right"><span class="style9">Age/Age Group </span></td>
<td><p>
<input name="age" type="text" id="age">
<span class="style5">(e.g: 20)</span></p></td>
</tr>
<tr>
<td align="right"><span class="style9">Todays Date </span></td>
<td><p>
<input name="date" type="text" id="date">
<span class="style5">(September 20,2004) <br>
</span></p> </td>
</tr>
<tr>
<td align="right"><span class="style9">Comments</span></td>
<td><textarea name="comments" cols="30" rows="5" id="comments"></textarea></td>
</tr>
<tr>
<td align="right"><span class="style9">State</span></td>
<td>
<p>
<select name="state" id="state">
<option value="">[choose yours]
<option value="008">Alabama
<option value="012">Alaska
<option value="016">Arizona
<option value="020">Arkansas
<option value="024">California
<option value="660">Colorado
<option value="010">Connecticut
<option value="028">Delaware
<option value="032">Florida
<option value="051">Georgia
<option value="533">Idaho
<option>Illinois
<option>Indiana
<option>Iowa
<option>Kansas
<option>Kentucky
<option>Louisiana
<option>Maine
<option>Maryland
<option>Massachusetts
<option>Michigan
<option>Minnesota
<option>Mississippi
<option>Missouri
<option>Montana
<option>Nebraska
<option>Nevada
<option>New Hampshire
<option>New Jersey
<option>New Mexico
<option>New York
<option>North Carolina
<option>North Dakota
<option>Ohio
<option>Oklahoma
<option>Oregon
<option>Pennsylvania
<option>Rhode Island
<option>South Carolina
<option>South Dakota
<option>Tennessee
<option>Texas
<option>Utah
<option>Vermont
<option>Virginia
<option>Washington
<option>West Virginia
<option>Wisconsin
<option>Wyoming
</select>
<br>
</p></td>
</tr>
<tr>
<td align="right"><span class="style9">
</span></td>
<td>
<p><span class="style10"><span class="style9">
<br>
<input type="checkbox" name="checkbox" value="checkbox">
</span>Join the Indie Xone mailing list.</span><br>
</p>
</td>
</tr>
<tr>
<td align="right"></td>
<td><input name="submit2" type="submit" value="Submit">
<INPUT name="reset" TYPE="reset" onClick="resetForm()" VALUE="Reset"> </td>
</tr>
</table>
</form>

<script language="JavaScript" type="text/javascript">
//You should create the validator only after the definition of the HTML form
var frmvalidator = new Validator("myform");
frmvalidator.addValidation("FirstName","req","Please enter your First Name");
frmvalidator.addValidation("FirstName","maxlen=20","Max length for FirstName is 20");
frmvalidator.addValidation("FirstName","alpha");

frmvalidator.addValidation("LastName","req");
frmvalidator.addValidation("LastName","maxlen=20");

frmvalidator.addValidation("bandname","req","Please enter your Band Name");
frmvalidator.addValidation("bandname","maxlen=20");
frmvalidator.addValidation("bandname","alpha");
// frmvaldiator.addvalidation("bandname","alpha");

frmvalidator.addValidation("Email","maxlen=50");
frmvalidator.addValidation("Email","req", "Please enter your email address");
frmvalidator.addValidation("Email","email");

frmvalidator.addValidation("genre","maxlen=50");
frmvalidator.addValidation("genre","alpha");

frmvalidator.addValidation("age","maxlen=50");
frmvalidator.addValidation("age","numeric");
frmvalidator.addValidation("age","req");

frmvalidator.addValidation("date","maxlen=50");
frmvalidator.addValidation("date","alnum");
frmvalidator.addValidation("date","req");

frmvalidator.addValidation("comments","maxlen=50");
frmvalidator.addValidation("comments","req");
frmvalidator.addValidation("state","dontselect=0");

// frmvalidator.addValidation("radiobutton","dontselect=0");

</script>

The above changes should fix your form validation problems but
next time you have a problem. Please only posted the relevant
code as I have done above. There is no need for us to read thru
your entire page codes. ;)

.....Willy

TTL
03-21-2004, 08:36 AM
Thanks alot for your help that fixed the newer problems I had!! Sorry for posting the wrong code, I just didn't know exactly what to post. Reading javascript to me is like the matrix lol I've been recking my brain all day trying to do this thing. So I updated what you told me to do and those areas work fine now, I'm wondering what I would have to do to make the radio buttons work and the check box validate as well. For the date, I thought that alnum meant that it lets you type in both letters and numbers? but I get an error message with that. I've been trying to find other codes online and impliment them into this form so it would all work together, but I haven't been very successful doing that. So here's the link (updated) and the code. http://www.indiexone.com/contactform.htm



<div id="Layer4" style="position:absolute; left:217px; top:154px; width:541px; height:38px; z-index:6" class="style3">
<p><strong>Contact Indie Xone!<br>
</strong><br>
<span class="style7">If you're an independent artist who wants to submit your information/music for consideration please include the following information:</span></p>
<ul>
<li><span class="style5">Your or your Bands Name</span></li>
<li><span class="style5">Where you are located</span></li>
<li><span class="style5">Your music genre</span></li>
<li><span class="style5">A link to your song</span></li>
<li><span class="style5">A link to a picture of yourself or your band</span></li>
<li><span class="style5">Any other information you want to include</span></li>
</ul>
<p><span class="style6">Everyone else please just send in your question or comment. </span></p>
</div>
<div id="Layer1" style="position:absolute; left:216px; top:370px; width:528px; height:425px; z-index:7"><form action="" name="myform" >
<table width="367" height="389" border="0" cellpadding="2" cellspacing="2">
<tr>
<td align="right"><span class="style9">First Name</span></td>
<td width="256"><input name="FirstName" type="text" id="FirstName"></td>
</tr>
<tr>
<td align="right"><span class="style9">Last Name</span></td>
<td><input name="LastName" type="text" id="LastName"></td>
</tr>
<tr>
<td align="right"><span class="style9">Band Name </span></td>
<td><p>
<input name="bandname" type="text" id="bandname">
</p> </td>
</tr>
<tr>
<td align="right"><span class="style9">E-Mail</span></td>
<td><input name="Email" type="text" id="Email"></td>
</tr>
<tr>
<td align="right"><span class="style9">Genre</span></td>
<td> <span class="style5">
<INPUT TYPE="radio" NAME="genre" onClick="radio_selection='pop'">
Pop
<input type="radio" name="genre" onClick="radio_selection='rnb'">
R&B
<INPUT TYPE="radio" NAME="genre" onClick="radio_selection='other'">
Other</span></td>
</tr>
<tr>
<td align="right"><span class="style9">Age/Age Group </span></td>
<td><p>
<input name="age" type="text" id="age">
<span class="style5">(e.g: 20)</span></p></td>
</tr>
<tr>
<td align="right"><span class="style9">Todays Date </span></td>
<td><p>
<input name="date" type="text" id="date">
<span class="style5">(September 20,2004) <br>
</span></p> </td>
</tr>
<tr>
<td align="right"><span class="style9">Comments</span></td>
<td><textarea name="comments" cols="30" rows="5" id="comments"></textarea></td>
</tr>
<tr>
<td align="right"><span class="style9">State</span></td>
<td>
<p>
<select name="state" id="state">
<option value="">[choose yours]
<option value="008">Alabama
<option value="012">Alaska
<option value="016">Arizona
<option value="020">Arkansas
<option value="024">California
<option value="660">Colorado
<option value="010">Connecticut
<option value="028">Delaware
<option value="032">Florida
<option value="051">Georgia
<option value="533">Idaho
<option>Illinois
<option>Indiana
<option>Iowa
<option>Kansas
<option>Kentucky
<option>Louisiana
<option>Maine
<option>Maryland
<option>Massachusetts
<option>Michigan
<option>Minnesota
<option>Mississippi
<option>Missouri
<option>Montana
<option>Nebraska
<option>Nevada
<option>New Hampshire
<option>New Jersey
<option>New Mexico
<option>New York
<option>North Carolina
<option>North Dakota
<option>Ohio
<option>Oklahoma
<option>Oregon
<option>Pennsylvania
<option>Rhode Island
<option>South Carolina
<option>South Dakota
<option>Tennessee
<option>Texas
<option>Utah
<option>Vermont
<option>Virginia
<option>Washington
<option>West Virginia
<option>Wisconsin
<option>Wyoming
</select>
<br>
</p></td>
</tr>
<tr>
<td align="right"><span class="style9">
</span></td>
<td>
<p><span class="style10"><span class="style9">
<br>
<input type="checkbox" name="checkbox" value="checkbox">
</span>Join the Indie Xone mailing list.</span><br>
</p>
</td>
</tr>
<tr>
<td align="right"></td>
<td><input name="submit2" type="submit" value="Submit">
<INPUT name="reset" TYPE="reset" onClick="resetForm()" VALUE="Reset"> </td>
</tr>
</table>
</form>

<script language="JavaScript" type="text/javascript">
//You should create the validator only after the definition of the HTML form
var frmvalidator = new Validator("myform");
frmvalidator.addValidation("FirstName","req","Please enter your First Name");
frmvalidator.addValidation("FirstName","maxlen=20","Max length for FirstName is 20");
frmvalidator.addValidation("FirstName","alpha");

frmvalidator.addValidation("LastName","req");
frmvalidator.addValidation("LastName","maxlen=20");

frmvalidator.addValidation("bandname","req","Please enter your Band Name");
frmvalidator.addValidation("bandname","maxlen=20");
frmvalidator.addValidation("bandname","alpha");
// frmvaldiator.addvalidation("bandname","alpha");

frmvalidator.addValidation("Email","maxlen=50");
frmvalidator.addValidation("Email","req", "Please enter your email address");
frmvalidator.addValidation("Email","email");

frmvalidator.addValidation("genre","maxlen=50");
frmvalidator.addValidation("genre","alpha");

frmvalidator.addValidation("age","maxlen=50");
frmvalidator.addValidation("age","numeric");
frmvalidator.addValidation("age","req");

frmvalidator.addValidation("date","maxlen=50");
frmvalidator.addValidation("date","alnum");
frmvalidator.addValidation("date","req");

frmvalidator.addValidation("comments","maxlen=50");
frmvalidator.addValidation("comments","req");
frmvalidator.addValidation("state","dontselect=0");

// frmvalidator.addValidation("genre","dontselect=0");

</script></div>
<script language="JavaScript" type="text/javascript">
//You should create the validator only after the definition of the HTML form
var frmvalidator = new Validator("myform");
frmvalidator.addValidation("FirstName","req","Please enter your First Name");
frmvalidator.addValidation("FirstName","maxlen=20",
"Max length for FirstName is 20");
frmvalidator.addValidation("FirstName","alpha");

frmvalidator.addValidation("LastName","req");
frmvalidator.addValidation("LastName","maxlen=20");

frmvalidator.addValidation("bandname","req","Please enter your Band Name");
frmvalidator.addValidation("bandname","maxlen=20");
frmvaldiator.addvalidation("bandname","alpha");

frmvalidator.addValidation("Email","maxlen=50");
frmvalidator.addValidation("Email","req", "Please enter your email address");
frmvalidator.addValidation("Email","email");

frmvalidator.addValidation("genre","maxlen=50");
frmvalidator.addValidation("genre","alpha");

frmvalidator.addValidation("age","maxlen=50");
frmvalidator.addValidation("age","numeric");
frmvalidator.addValidation("age","req");

frmvalidator.addValidation("date","maxlen=50");
frmvalidator.addValidation("date","alnum");
frmvalidator.addValidation("date","req");

frmvalidator.addValidation("comments","maxlen=50");
frmvalidator.addValidation("comments","req");
frmvalidator.addValidation("state","dontselect=0");

frmvalidator.addValidation("genre","dontselect=0");

</script>
<div id="Layer2" style="position:absolute; left:563px; top:117px; width:216px; height:32px; z-index:2">
<FORM ACTION="search.php" METHOD="GET">
<INPUT TYPE="Text" NAME="query" SIZE="20">
<INPUT TYPE="Hidden" NAME="stpos" VALUE="0">
<INPUT name="Submit" TYPE="Submit" VALUE="Search">
</FORM>
</div>

Garadon
03-21-2004, 11:29 AM
I think your rigth about alnum is to allow letters and numbers.

but that would logicaly exclude any other sign
which include:
comma:','
space:' '

that your using in ur date field

TTL
03-21-2004, 07:06 PM
oh ok I understand that , any idea where i can find the script for the radio buttons and check box?

glenngv
03-22-2004, 08:56 AM
Check out beetle's fValidate script (http://www.peterbailey.net/fValidate/).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum