Post form into dialog window by clicking a link
-
09-10-2019 - |
Question
I'm trying to make this piece of code work.
<form name="myform" onsubmit="alert('1');"> </form>
<a href="javascript: void(0);" onclick="document.myform.submit();">ok</a>
However nothing happens when I click "ok". Where have I mistaken?
Solution
The browser does not trigger the
onsubmit
event if you call thesubmit
method programmatically. Therefore, if the form is using the form validator script, call theonsubmit
method also to trigger the validation.
http://www.javascript-coder.com/javascript-form/javascript-form-submit.phtml (there's also an example)
So, your form is posted but onsumbit
is not triggered.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow