How to submit a form OnKeyPress with Javascript?

為{幸葍}努か 提交于 2019-12-11 11:24:35

问题


I want to make a form like this, and i want to post the form - with javascript - in all the keydowns.

<form action="{$formaction}" enctype="multipart/form-data" method="post">
<input type="text" name="n">
<input type="password" name="pw">
<button name="in" type="submit">enter</button>
</form>

please tell me how to do this.


回答1:


<form onkeydown="this.submit();">
  <!-- form content -->
</form>



回答2:


<body onkeydown="document.forms["myform"].submit();">



回答3:


If you do that, the page will reload, just as if you were clicking the submit button. What you probably want is to attach an onkeydown handler to the password field and submit key presses via AJAX.

For an example look at one of javascript auto-suggest libraries, e.g. AJAX Auto Suggest.



来源:https://stackoverflow.com/questions/2614856/how-to-submit-a-form-onkeypress-with-javascript

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