I want to add some logic before form submission. it's work when i click on submit button. but there is another button which submit the form via JavaScript and my logic doesn't call on that. below is the snippet for reference.
<form action="text" method="get">
<input type="submit">
</form>
<script>
document.forms[0].onsubmit = function(){
alert('hi');
};
//document.forms[0].submit();
</script>
when i manually click on submit button, alert comes. but after un-commenting the second line document.forms[0].submit();
nothing comes.
It'll be also helpful to get explanation for this behavior. as i understand submit handler should be trigger on both cases.
any help will be much appreciated.`