最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

post - How to submit a form OnKeyPress with Javascript? - Stack Overflow

programmeradmin3浏览0评论

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.

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.

Share Improve this question asked Apr 10, 2010 at 20:28 RépásRépás 1,8208 gold badges28 silver badges55 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 4
<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)

  1. 暂无评论