There's a great answer here on how to intercept SUBMIT using addEventListener on a form. It works great as long as the form is submitted either via Submit button (or ENTER).
It's totally ignored though when fired like this:
document.getElementById('myform').submit();
How would you intercept such call?
Here's the example:
<script>
function checkRegistration(){
var form_valid = (document.getElementById('some_input').value == 'google');
if(!form_valid){
alert('Given data is incorrect');
return false;
}
return true;
}
</script>
<form onsubmit="return checkRegistration()" method="get" action="http://google.com" id='myform'>
Write google to go to google..<br/>
<input type="text" id="some_input" value=""/>
<input type="submit" value="google it"/>
</form>
<a href="javascript:document.getElementById('myform').submit();">Ignore validation</a>