|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Validation Checks
I have a Registration form below, and I want to make sure that the users input data into all the fields before pressing submit. If a user does not enter anything, then I want a message box saying ‘You have not completed all fields’. They will only be able to submit their details once they have filled out all the fields. (The field Address2 can be left empty) How would I do this?
Below is the code that I am using for my registration form. Thanks in advance <html> <head> <SCRIPT language="JavaScript"> <!-- function VerifyData() { if (document.frmUser.txtPassword.value != document.frmUser.txtVerifyPassword.value) { alert ("Your passwords do not match - please reenter"); return false; } else return true; } --> </SCRIPT> <title>Registration Form</title> </head> <body> <input type="button" onClick="document.all.content.style.zoom=(document.all.cont ent.style.zoom==1?2:1);" value="ENLARGE TEXT"> <div id="content"> <H1 align="center"><font face="Arial"><u>Registration Form</u></font></H1> <form action = "adduser1.asp" name="frmUser" method = "post" onSubmit="return VerifyData()"> Title <input type="text" name = "txtTitle"><br> First Name <input type="text" name = "txtFirstName"><br> Surname <input type="text" name = "txtSurname"><br> Address1 <input type="text" name = "txtAddress1"><br> Address2 <input type="text" name = "txtAddress2”><BR> Town <input type="text" name = "txtTown"><br> County <input type="text" name = "txtCounty"><br> Post Code <input type="text" name = "txtPostCode"><br> Telephone Number <input type="text" name = "txtTelephoneNo"><br> Email Address <input type="text" name = "txtEmailAddress"><br> Username <input type="text" name = "txtUsername"><br> Password <input type="password" name = "txtPassword"><br> Verify Password <input type="password" name = "txtVerifyPassword"><br> <INPUT TYPE="SUBMIT" VALUE="Submit"> <INPUT TYPE="RESET" VALUE="Clear"></font></P> </form> <p><font face="Arial"><a href="home.asp">HOME</a></font></p> </div> </body> </html> |
|
#2
|
|||
|
|||
|
first, in your onsubmit call to VerifyData, use the keyword this so that in your function you don't need to keep using document.frmUser:
onSubmit="return VerifyData(this);" then in your function, use a true/false variable to keep track of whether the form is okay, and a string variable to keep track of your error messages. you can keep adding error messages for each field there's a problem with, if you want, which is how i set this up... Code:
function VerifyData(form) {
formOk = true;
errorMsg = "";
if (form.txtPassword.value != form.txtVerifyPassword.value) {
formOk = false;
errorMsg = errorMsg + "Your passwords do not match - please reenter/n/n";
}
if (form.txtTitle.value == "") {
formOk = false;
errorMsg = "Enter a title/n";
}
if (form.txtFirstName.value == "") {
formOk = false;
errorMsg = "Enter a first name/n";
}
// do the same error checks for empty fields for the remaining fields
if (!formOk) {
alert(errorMsg);
}
return formOk;
}
|
|
#3
|
||||
|
||||
|
And in case you want to go slightly farther in the same direction here are a couple JavaScript validation resources:
Javascript Field Validations -- Client Side Scripting by Nannette Thacker - 8/19/1999 http://www.shiningstar.net/articles...tions.asp?ID=AW Form Validation Using Javascript - 9/19/1998 http://www.4guysfromrolla.com/webtech/091998-1.shtml
__________________
J. Paul Schmidt www.Bullschmidt.com - Freelance Web and Database Developer www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips |
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > Validation Checks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|