Post form into dialog window by clicking a link

耗尽温柔 提交于 2019-12-25 08:15:04

问题


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?


回答1:


The browser does not trigger the onsubmit event if you call the submit method programmatically. Therefore, if the form is using the form validator script, call the onsubmit 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.



来源:https://stackoverflow.com/questions/3968922/post-form-into-dialog-window-by-clicking-a-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!