Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-18-2012, 05:54 PM   PM User | #1
ajgosling
New to the CF scene

 
Join Date: May 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ajgosling is an unknown quantity at this point
Javascript form validation before submission

Hello there, I hope you might be able to help me with an issue I'm having getting a form to validate before submission. I've been trying to figure out where I'm going wrong but being relatively new to javascript I'm obviously missing something.

I have a form which calls one of two validation scripts with onBlur for each field (I've only included one of each field, there are 8 fields in total in the form):

Code:
    <form name="submitrunnertime" action="http://......reflect.php" onsubmit="return valResultsForm();" method="post">

    <table>
      
      <tr><td><label for="RunnerID">Runner ID</label></td>
	<td><input type="text" name="RunnerID" size="5" maxlength="5" onBlur="valRange(RunnerID, 1, 99999, 'RunnerID_bk');" />
	</td><td id="RunnerID_bk"><span></span></td></tr>
      
      <tr><td><label for="">Date (YYYY-MM-DD)</label></td>
	<td><input type="text" name="Date" size="10" maxlength="10" onBlur="valExpression(Date, '^(19[0-9{2}|20[01][0-9])\-(0[1-9]|1[012])\-([012][0-9]|3[01])$', 'Date_bk', 'please use indicated format');" />
	</td><td id="Date_bk"><span></span></td></tr>
      
 etc. etc.

    </table>
    
    <input type="submit" name="submitrunnertime" value="submit">
    </form>
I've managed to get each individual field to validate as the form is filled in.

Now, if I fill valResultsForm.js with a simple line return false; then the form refuses to submit as it should do, but if I try and re-run the validation of each field so that the form will only submit if all fields have been filled in correctly, even if I force valResultsForm to return a false result, the form still submits. I just can't figure out why it is doing this and it's driving me around the bend.

valResultsForm looks like:

Code:
function valResultsForm() {

    var res1 = valRange(RunnerID, 1, 99999, 'RunnerID_bk');

    var res2 = valExpression(Date, '^(19[0-9{2}|20[01][0-9])\-(0[1-9]|1[012])\-([012][0-9]|3[01])$', 'Date_bk', 'please use indicated format');

    if (res1 == true && res2 == true) {
	return true;
    }
    else { return false; }

}
Any hints or advice that anyone could give me would be hugely appreciated.

Thank you, Andrew
ajgosling is offline   Reply With Quote
Old 05-21-2012, 06:39 PM   PM User | #2
jalarie
Regular Coder

 
Join Date: Jun 2002
Location: Flint, Michigan, USA
Posts: 595
Thanks: 1
Thanked 20 Times in 20 Posts
jalarie is an unknown quantity at this point
Please tell us what those two validation routines (valRange, valExpression) look like.
__________________
Visit my site at http://spruce.flint.umich.edu/~jalarie/.
jalarie is offline   Reply With Quote
Reply

Bookmarks

Tags
form, javascript, validation

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:45 PM.


Advertisement
Log in to turn off these ads.