Jump to content

Validation


see

Recommended Posts

You're going to need to make an effort yourself before you can expect anyone to help you. Start on the script and do what you can. When you run into a problem, post your question and the relevant code and people will be able to help. There are several scripts online if you don't want to build your own.

Link to comment
Share on other sites

You're going to need to make an effort yourself before you can expect anyone to help you. Start on the script and do what you can. When you run into a problem, post your question and the relevant code and people will be able to help. There are several scripts online if you don't want to build your own.
Here is my code, I have tried this no error and no sign of validation.also I need help for the (PASSWORD and RE-PASSWORD) Validation.my javascript code<script LANGUAGE="JavaScript">function noEntry() {surname=document.isn.empty.value;if ((surname.length<1)||(surname.substring(0,20)=="******")) {alert("Enter Surname");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return true;}function noEntry() {firstname=document.isn.empty.value;if ((firstname.length<1)||(firstname.substring(0,20)=="******")) {alert("Enter First-Name");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return true;}function noEntry() {dob=document.isn.empty.value;if ((dob.length<1)||(dob.substring(0,10)=="******")) {alert("Enter Date of Birth + yyyy-mm-dd");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return true;}function noEntry() {######=document.isn.empty.value;if ((######.length<1)||(######.substring(0,6)=="******")) {alert("Select your ######");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return true;}function noEntry() {category=document.isn.empty.value;if ((category.length<1)||(category.substring(0,20)=="******")) {alert("Select Category");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return true;}function noEntry() {address=document.isn.empty.value;if ((address.length<1)||(address.substring(0,20)=="******")) {alert("Enter you Address");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return true;}function noEntry() {state=document.isn.empty.value;if ((state.length<1)||(state.substring(0,20)=="******")) {alert("Enter Your State of Origin");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return true;}function emailCheck() {txt=document.isn.email.value;if (txt.indexOf("@")<3){alert("Enter your email correctly"+" check the prefix and '@' sign.");}if ((txt.indexOf(".com")<5)&&(txt.indexOf(".org")<5)&&(txt.indexOf(".gov")<5)&&(txt.indexOf(".net")<5)&&(txt.indexOf(".mil")<5)&&(txt.indexOf(".edu")<5)){alert("Enter a valid email. Please"+" check the suffix for accuracy. (It should include a "+".com, .edu, .net, .org, .gov or .mil)"); }}function noEntry() {telephone=document.isn.empty.value;if ((telephone.length<1)||(telephone.substring(0,20)=="******")) {alert("Enter Your Telephone");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return true;}function noEntry() {username=document.isn.empty.value;if ((username.length<1)||(username.substring(0,50)=="******")) {alert("Enter Username");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return true;}function noEntry() {password=document.isn.empty.value;if ((password.length<1)||(password.substring(0,50)=="******")) {alert("Enter Password");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return true;}</SCRIPT>
Link to comment
Share on other sites

You're trying to define one function several times, that isn't how Javascript works. Each function needs its own name. You can't have many functions called noEntry, only one function with that name. The one function can do validation for all of your fields though.Your functions are all very similar, they all do the same things. Every time you get the same value:document.isn.empty.value;That is not the name of every value in your form, that's only one value. Even so, it's hard to offer a whole lot of other suggestions without seeing the HTML part of this. If you're trying to get a function to run for the form's onsubmit event, then it needs to return false to stop the form from submitting. Your functions are all returning only true, they need to return false if they want to stop the submit.

Link to comment
Share on other sites

Please I think I really help on this javascript. I tried again no error no validation action.Here is my full html code with the javascript.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>onLoad and onUnload Example</title> <title>Registration</title> <meta http-equiv="Content-Language" content="English" /> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="author" content="A.C.E)" /> <meta name="description" content="Design by RuudCreations" /> <meta name="keywords" content="xhtml,css,template,webdesign" /> <meta name="Robots" content="index,follow" /> <link href="ACE.css" rel="stylesheet" type="text/css" /> <style type="text/css"><!--.style1 { font-size: 10px; font-weight: bold; color: #FFFFFF;}.style2 { font-size: 9px; font-weight: bold; color: #FFFFFF;}.style3 {color: #FF0000}.style4 {color: #FFFFFF}.style5 {color: #003300}.style8 {color: #FF0000; font-size: 9px; }.style13 {font-size: 9px; font-weight: bold; color: #000000; }.style14 {font-size: 9px}--> </style> <script LANGUAGE="JavaScript">function surname() {surname=document.isn.empty.value;if ((surname.length<1)||(surname.substring(0,20)=="******")) {alert("Enter Surname");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return false;}function firstname() {firstname=document.isn.empty.value;if ((firstname.length<1)||(firstname.substring(0,20)=="******")) {alert("Enter First-Name");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return false;}function dob() {dob=document.isn.empty.value;if ((dob.length<1)||(dob.substring(0,10)=="******")) {alert("Enter Date of Birth + yyyy-mm-dd");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return false;}function ######() {######=document.isn.empty.value;if ((######.length<1)||(######.substring(0,6)=="******")) {alert("Select your ######");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return false;}function category() {category=document.isn.empty.value;if ((category.length<1)||(category.substring(0,20)=="******")) {alert("Select Category");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return false;}function address() {address=document.isn.empty.value;if ((address.length<1)||(address.substring(0,20)=="******")) {alert("Enter you Address");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return false;}function state() {state=document.isn.empty.value;if ((state.length<1)||(state.substring(0,20)=="******")) {alert("Enter Your State of Origin");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return false;}function email() {txt=document.isn.email.value;if (txt.indexOf("@")<3){alert("Enter your email correctly"+" check the prefix and '@' sign.");}if ((txt.indexOf(".com")<5)&&(txt.indexOf(".org")<5)&&(txt.indexOf(".gov")<5)&&(txt.indexOf(".net")<5)&&(txt.indexOf(".mil")<5)&&(txt.indexOf(".edu")<5)){alert("Enter a valid email. Please"+" check the suffix for accuracy. (It should include a "+".com, .edu, .net, .org, .gov or .mil)"); }}function telephone() {telephone=document.isn.empty.value;if ((telephone.length<1)||(telephone.substring(0,20)=="******")) {alert("Enter Your Telephone");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return false;}function username() {username=document.isn.empty.value;if ((username.length<1)||(username.substring(0,50)=="******")) {alert("Enter Username");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return false;}function password() {password=document.isn.empty.value;if ((password.length<1)||(password.substring(0,50)=="******")) {alert("Enter Password");document.isn.empty.value="******Please Complete This Entry";document.isn.empty.focus();}return false;}</SCRIPT></head> <body> <?php include("header.php"); ?> <div id="container"> <div id="container-header"></div> <div id="container-eyecatcher"><img src="images/AceDesign.gif" alt="Ace Picture" /> <div id="container-navigation"> <ul id="navigation"> <li><a href="index.html">Home</a></li> <li><a href="aboutus.html">About Us</a></li> <li><a href="board.html">Board</a></li> <li><a href="info.html">Information</a></li> <li><a href="ranking.html">Ranking</a></li> <li><a href="calendar.html">Calendar</a></li> <li><a href="contact.html">Contact Us </a></li> </ul> </div> </div> <div id="container-content"> <div id="content"> <h1> Registration</h1> <form id="form1" method="post" action="insert.php" onsubmit="return validate_form(this);" > <table width="428"> <!--DWLayoutTable--> <tr bgcolor="#CCCCCC"> <td width="133"> </td> <td width="279"> </td> </tr> <tr bgcolor="#FFFFFF"> <td><strong>SURNAME *</strong></td> <td><label> <input name="surname" type="text" id="surname" onblur="MM_validateForm('surname','','R','firstname','','R','address','','R','state','','R','email','','RisEmail','telephone','','NisNum','username','','R','password','','R');return document.MM_returnValue" size="45" maxlength="20" /> </label></td> </tr> <tr bgcolor="#CCCCCC"> <td> </td> <td> </td> </tr> <tr bgcolor="#FFFFFF"> <td><strong>MIDDLE-NAME</strong></td> <td><label> <input name="middlename" type="text" id="middlename" size="45" maxlength="20" /> </label></td> </tr> <tr bgcolor="#CCCCCC"> <td> </td> <td> </td> </tr> <tr bgcolor="#FFFFFF"> <td><strong>FIRST- NAME <span class="style3">*</span> </strong></td> <td><strong> <label></label> <input name="firstname" type="text" size="45" maxlength="20" id="firstname" /> </strong></td> </tr> <tr bgcolor="#CCCCCC"> <td> </td> <td> </td> </tr> <tr bgcolor="#FFFFFF"> <td><strong>DOB (yyyy-mm-dd) <span class="style3">* </span></strong></td> <td><input name="dob" type="text" id="textfield3" size="45" maxlength="10" /></td> </tr> <tr bgcolor="#CCCCCC"> <td> </td> <td> </td> </tr> <tr bgcolor="#FFFFFF"> <td><strong>###### <span class="style3">* </span></strong></td> <td><label> <select name="######" id="######"> <option>NONE</option> <option>MALE</option> <option>FEMALE</option> </select> </label></td> </tr> <tr bgcolor="#CCCCCC"> <td> </td> <td> </td> </tr> <tr bgcolor="#FFFFFF"> <td><strong>CATEGORY <span class="style3">*</span></strong></td> <td><label> <select name="Category" id="Category"> <option>NONE</option> <option>PROFESSIONAL</option> <option>UNDER 18</option> <option>UNDER 16</option> <option>UNDER 14</option> <option>UNDER 12</option> </select> </label></td> </tr> <tr bgcolor="#CCCCCC"> <td> </td> <td> </td> </tr> <tr bgcolor="#FFFFFF"> <td><strong>ADDRESS * </strong></td> <td><input name="address" type="text" id="address" size="45" maxlength="50" /></td> </tr> <tr bgcolor="#CCCCCC"> <td> </td> <td> </td> </tr> <tr bgcolor="#FFFFFF"> <td><strong>ADDRESS 2 </strong></td> <td><input name="Address2" type="text" id="Address2" size="45" maxlength="50" /></td> </tr> <tr bgcolor="#CCCCCC"> <td> </td> <td> </td> </tr> <tr bgcolor="#FFFFFF"> <td><strong>STATE *</strong></td> <td><input name="state" type="text" id="state" size="45" maxlength="20" /></td> </tr> <tr bgcolor="#CCCCCC"> <td> </td> <td> </td> </tr> <tr bgcolor="#FFFFFF"> <td><strong>EMAIL *</strong></td> <td><input name="email" type="text" id="email" size="45" maxlength="50" /></td> </tr> <tr bgcolor="#CCCCCC"> <td> </td> <td> </td> </tr> <tr bgcolor="#FFFFFF"> <td><strong>TELEPHONE *</strong></td> <td><label> <input name="telephone" type="text" id="telephone" size="45" maxlength="20" /> </label></td> </tr> <tr bgcolor="#CCCCCC"> <td> </td> <td> </td> </tr> <tr bgcolor="#FFFFFF"> <td><strong>USERNAME * </strong></td> <td><label> <input name="username" type="text" id="username" size="45" maxlength="50" /> </label></td> </tr> <tr bgcolor="#CCCCCC"> <td> </td> <td> </td> </tr ><tr bgcolor="#FFFFFF"> <td><strong>PASSWORD * </strong></td> <td><label> <input name="password" type="password" id="password" size="45" maxlength="50" /> </label></td> </tr> <tr bgcolor="#CCCCCC"> <td height="23"></td> <td></td> </tr> <tr bgcolor="#FFFFFF"> <td height="23"><strong>RE-PASSWORD *</strong></td> <td><label> <input name="password" type="password" id="password" size="45" maxlength="50" /> </label></td> </tr> <tr bgcolor="#CCCCCC"> <td height="23"></td> <td></td> </tr> </table> <p align="center"> <label> <input type="submit" name="Submit" value="Submit" /> <span class="style4"> .</span> </label> <label> <input name="Reset" type="reset" id="Reset" value="Reset" /> </label> </p> <p><span class="style8"><strong>Notice</strong>:</span><span class="style13"> Payment must be made to NTF PIN account before registration to obtain your PIN. This will enable players to send entries for tournament online. Players are expected to pay a fee of five thousand naira (=N=5,000.00) yearly to renew the PIN. Players must ensure to make payment in their names. </span></p> <p><span class="style13">Guaranty Trust Bank.... Account Name: NTF PIN Account Number: XXXX XXXX XXXX</span> </p> <div align="center" class="style5"></div> </form> </div> <div id="border"> <h4><img src="images/pics4.gif" alt="" width="187" height="288" /></h4> <hr /> <hr /> <h4> </h4> <p> </p> </div> </div> <div id="container-footer"> <div id="footer"></div> <div align="center" class="style1">copyright©2010 Nigeria Tennis Federation . All right reserved </div> <div align="center" class="style2">webmaster: sundayessien@yahoo.com</div> </div> </div> </body></html>

Link to comment
Share on other sites

do you have errors turned on?there's an error just from typing something into one of the input elements.also, why is every function only checking document.isn.empty.value? what is that?It looks like the only time any form validation is done is on blur of one of your input elements. I'm not sure that's what you want to be doing. You should probably have the validation script run after the submit button is pressed, unless you want to do input by input, dynamic validation, which it kinda seems like what you're trying to do, but I personally don't think you understand the basics enough. What you have now is a bunch of functions all validating the same a non existent form element's value. On top of that, the validation is happening onBlur() of an input element, which means there's no guarantee that's going to be the last one filled out, especially when its the third one. And its not really doing anything either, since it doesn't exist.What you should do is have the form validate on submit by using document.getElementById() to get the value of all the various input elements and validate them, either in one giant functions, or in separate functions all called within one function.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...