开发者

How to submit a form OnKeyPress with Javascript?

开发者 https://www.devze.com 2022-12-26 03:19 出处:网络
I want to make a form like this, and i want to po开发者_如何学编程st the form - with javascript - in all the keydowns.

I want to make a form like this, and i want to po开发者_如何学编程st 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.


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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消