form.addEventListener('submit', e => {
e.preventDefault();
validateInputs();
});
how to submit the form in given js
CodePudding user response:
It is not very clear from your question, but I will make this assumption:
- I will assume that the function
validateInputs
returnstrue
if all the inputs are considered valid, and returnsfalse
if there is one or more error found in the form inputs.
You can call form.submit()
to programmatically submit the form.
In the context of your existing code, applying the assumption I've listed above:
form.addEventListener('submit', e => {
e.preventDefault();
if (validateInputs()) {
// All inputs are valid, submit the form.
form.submit();
} else {
// Run some code here that points out the problems in the form
}
});
CodePudding user response:
find your submit button and add click event
function checkForm()
{
if(validateInputs())
{
form.submit();
}
}
button.addEventListener("click",checkForm);