javascript form submit event code example
Example 1: js form submit listener
document.getElementById("#myFormId").addEventListener("submit", function(e){
if(!isValid){
e.preventDefault(); //stop form from submitting
}
//do whatever an submit the form
});
Example 2: javascript submit a form
document.getElementById("myFormID").submit();
Example 3: javascript submit form
document.getElementById("myForm").submit();
Example 4: how to run js before submit html
<form onsubmit="return do_something()">
function do_something(){
// Do your stuff here
return true; // submit the form
return false; // don't submit the form
}
Example 5: javascript submit form
document.forms["myform"].submit();