form.addEventListener('submit', e => {
e.preventDefault();
validateInputs();
});
how to submit the form in given js
It is not very clear from your question, but I will make this assumption:
validateInputs returns true if all the inputs are considered valid, and returns false 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
}
});
find your submit button and add click event
function checkForm()
{
if(validateInputs())
{
form.submit();
}
}
button.addEventListener("click",checkForm);