Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
JavaScript
<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

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:
JavaScript
function validateit() {
  // do validation stuff
  if validated { return true; }
  return false;
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900