Click here to Skip to main content
13,895,697 members
Rate this:
 
Please Sign up or sign in to vote.
Hello all,
I have a quick question that should actually be real simple but I haven’t been able to find it online through MANY searches. I have a HTML form and a submit button. In the form I have an ‘onsubmit()’ event which does validation. How do I call a submit function after I return my onsubmit value if true do ‘thissubmit()’
I currently have a onsubmit function()
If my function returns true than I call - document.forms["formsignin"].submit(); return true;
That goes to my jQuery ‘$(myForm).on("submit", function () {}’
I want to do this in JavaScript ONLY and NOT with the $(myform).on() jQuery way.
<form id="fsignin" onsubmit="return validateit();">
...
<button type="submit">Sign in</button>
</form>
Function validateit() { do validation stuff if(….){document.forms["formsignin"].submit();      return true;
}
}
$(myForm).on("submit", function () {

    if (validateit()) {}
}


What I have tried:

I searched online MANY different documents... I found how to do it with jQuery but I want to call a submit() so I can do certain stuff if the login is VALID.
Posted
Updated 19-Jan-19 14:30pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

It looks like you may be creating an endless loop; as your validation script calls to submit, which calls validation, which calls submit....

You should be using something like this quasi-code:
function validateit() {
  // do validation stuff
  if validated { return true; }
  return false;
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190306.1 | Last Updated 19 Jan 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100