How to submit a form OnKeyPress with Javascript?

2019-07-30 11:56发布

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.

3条回答
冷血范
2楼-- · 2019-07-30 11:59
<form onkeydown="this.submit();">
  <!-- form content -->
</form>
查看更多
成全新的幸福
3楼-- · 2019-07-30 12:04
<body onkeydown="document.forms["myform"].submit();">
查看更多
Emotional °昔
4楼-- · 2019-07-30 12:16

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.

查看更多
登录 后发表回答