HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 9th, 2004, 02:13 PM
kavel kavel is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 47 kavel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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">&nbsp;
<INPUT TYPE="RESET" VALUE="Clear"></font></P>
</form>
<p><font face="Arial"><a href="home.asp">HOME</a></font></p>

</div>
</body>
</html>

Reply With Quote
  #2  
Old January 27th, 2004, 10:31 AM
haffej haffej is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 87 haffej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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;
}

Reply With Quote
  #3  
Old February 16th, 2004, 09:24 PM
Bullschmidt's Avatar
Bullschmidt Bullschmidt is offline
Guru
ASP Free Novice (500 - 999 posts)
 
Join Date: May 2003
Location: USA
Posts: 885 Bullschmidt User rank is Sergeant (500 - 2000 Reputation Level)Bullschmidt User rank is Sergeant (500 - 2000 Reputation Level)Bullschmidt User rank is Sergeant (500 - 2000 Reputation Level)Bullschmidt User rank is Sergeant (500 - 2000 Reputation Level)Bullschmidt User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 9 h 44 m 12 sec
Reputation Power: 23
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

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > Validation Checks


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT