Skip to main content
Inspiring
October 23, 2015
Answered

jquery is overriding the JS validation

  • October 23, 2015
  • 1 reply
  • 880 views

Hi,

I am using this JS validation

JavaScript Form Validation : quick and easy!

and by itself it works well

but also I am using jQuery with forms and it seems to be over riding the validation and just processing the form anyway

Q: How do I set it up so jQuery form can wait for validation to work 1st?

Thanks in advance

This topic has been closed for replies.
Correct answer Nancy OShea

Is there some reason you can't use HTML5 form validation?

A Simple HTML5 Form Validation - JSFiddle

Nancy O.

1 reply

Nancy OShea
Community Expert
Community Expert
October 23, 2015

I prefer to put validation into my server-side form-processing script.

Client side validation is not foolproof.

Nancy O'Shea— Product User & Community Expert
revdaveAuthor
Inspiring
October 25, 2015

Hi Nancy,


Agreed, however right now I would like to know how to make this work for my current project


Here is the code from here ...


http://www.javascript-coder.com/html-form/javascript-form-validation.phtml

Now I just need to figure out how to = add post code AFTER the form has successfully validated.

my laymen version...

1 - test here

2 - if success....

alert ("success");

then add more code like... $.post('https://mysite.com/test.php', { password: pass, ...... etc.

3 - if fail - then

alert ("fail");

Any idea how to set this up with this code from this site?

<!DOCTYPE html>

<html>

<head>

<title>test</title>

<style type="text/css" xml:space="preserve">

BODY, P,TD{ font-family: Arial,Verdana,Helvetica, sans-serif; font-size: 10pt }

A{font-family: Arial,Verdana,Helvetica, sans-serif;}

B { font-family : Arial, Helvetica, sans-serif; font-size : 12px; font-weight : bold;}

.error_strings{ font-family:Verdana; font-size:14px; color:#F00; }

</style>

<script src="gen_validatorv4.js" type="text/javascript" >

</script>

</head>

<body>

<form action="" method="POST" id="nowform">

<div class="box1 center1">

<p>enter PASSWORD<br>

<div id='nowform_pass_errorloc' class="error_strings"></div>

<input id="pass" name="pass" type="password" size="15" class="print_data_22" />

</p>

<input type="submit"  />

</form>

<script>

alert ("test1");

var frmvalidator = new Validator("nowform");

frmvalidator.EnableOnPageErrorDisplay();

frmvalidator.EnableMsgsTogether();

frmvalidator.addValidation("pass","req","Please enter your pass");

frmvalidator.addValidation("pass","maxlen=15", "Max length for pass is 15");

alert ("test2");

//start post code... WHERE DO I PUT THIS POST CODE?

$.post('http://mysite.com/getstuff.php', { ... etc...

</script>

</body>

</html>

Nancy OShea
Community Expert
Nancy OSheaCommunity ExpertCorrect answer
Community Expert
November 1, 2015

Is there some reason you can't use HTML5 form validation?

A Simple HTML5 Form Validation - JSFiddle

Nancy O.

Nancy O'Shea— Product User & Community Expert