开发者

How to submit a form OnKeyPress with Javascript?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜