0

I have a quick question that should actually be really simple but I haven’t been able to find it online through MANY searches. I have an 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 then 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()) {
    }

}

2 Answers 2

1

Your formatting is not correct. You have a submit attribute and a submit event via jQuery. You only need one, or addEventListener for JS.

The name or id of your form is wrong.

You then wouldn't call submit, just return true to continue with submission.

Try to study different approaches in isolation. You need to understand them before, if desired, you consider combining them

Sign up to request clarification or add additional context in comments.

Comments

0

First, validate each condition on onSubmit() function and use onclick method in html button to call this function. If that condition is true then will go to next condition and so on. If all conditions are true then submit the form. If not then return false and exit the function.

Example:

onSubmit(){
    if(!validateCondition1){
        enter code here
        return false;
    }
    if(!validateCondition2){
        enter code here
        return false;
    }
     ....submit code.....
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.