I have a HTML form with button:
<form action="/" method="post" id="MyForm">
<input type="hidden" name="Field1" value="Value1" />
<input type="hidden" name="Field2" value="Value2" />
<input type="submit" name="name" value="submit" />
</form>
I have event handler for submit attached to Window:
window.onsubmit = function()
{
alert("Submit happening!");
};
This event handler fires properly if I click "Submit" button.
However events never works when submit is triggered programmatically from javascript:
$("#MyForm")[0].submit();
How to catch submit event handler when it was initiated by Javascript, not by User click?
I tried to subscribe for Form event using Jquery or AddEventListener - does not work.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…