|
|
Subject:
java script - validation routine (easy question)
Category: Computers > Internet Asked by: teacholddognewtricks-ga List Price: $4.00 |
Posted:
12 Sep 2004 23:46 PDT
Expires: 12 Oct 2004 23:46 PDT Question ID: 400393 |
I have a simple validation routine. All code is posted below, as well as the submit button code. I can run it fine with the first two validations, but when I add the validation for the city field, I get an error and if I click No to stop it opens the page I am calling. Can I only validate 2 fields??? If so, how can I validate more. When I take all this code off and just set the properties on the fields, that validation process does not kick in and check fields before moving on. Below is my code.... It is as follows: <script language="JavaScript" type="text/javascript"> function validate(FrontPage_Form1){ if (document.FrontPage_Form1.LastName.value.length<2) { window.alert('Please enter a full last name.'); return false; } return true; if (document.FrontPage_Form1.FirstName.value.length<2) { window.alert('Please enter a full First name.'); return false; } return true; if (document.FrontPage_Form1.City.value.length<1) { window.alert('Please enter a valid city.'); return false; } return true; } </script> The is the form info <form method="POST" action="https:(my file name here)" target="_parent" onsubmit="return FrontPage_Form1_Validator(this)" name="FrontPage_Form1" language=javascript> the submit button code is this: <input type="submit" onClick="javascript:return validate(this); " value="Submit"> |
|
Subject:
Re: java script - validation routine (easy question)
Answered By: palitoy-ga on 13 Sep 2004 01:40 PDT Rated: |
Hello teacholddognewtricks I believe the problem you are having is due to additional "return true;" lines, you should only "return true;" after the final if statement check (which means you can add as many more as you like as long as they do not have any additional "return true" statements after them). When I run the script below I have to enter data into all three fields before I can carry on. <script language="JavaScript" type="text/javascript"> function validate(FrontPage_Form1){ if (document.FrontPage_Form1.LastName.value.length<2) { window.alert('Please enter a full last name.'); return false; } if (document.FrontPage_Form1.FirstName.value.length<2) { window.alert('Please enter a full First name.'); return false; } if (document.FrontPage_Form1.City.value.length<1) { window.alert('Please enter a valid city.'); return false; } return true; } </script> If you need any further help on this please ask for clarification and I will do my best to respond quickly. |
teacholddognewtricks-ga
rated this answer:
and gave an additional tip of:
$4.00
Thank you!!! It worked!! I'm sorry it took so long to respond. I was having technical problems and had to wait for the hosting service to reset frontpage extensions. Thank you, again! |
|
Subject:
Re: java script - validation routine (easy question)
From: thekok-ga on 17 Sep 2004 11:06 PDT |
The return true is first problem . Second problem I can see is : You should do the validate(this) on the onsubmit instead of onclick. Like this : The is the form info <form method="POST" action="https:(my file name here)" target="_parent" onsubmit="return validate(this);" name="FrontPage_Form1" language=javascript> the submit button code is this: <input type="submit" value="Submit"> |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |