admin管理员组文章数量:1316843
I have a text input
<input type="text" name="invCode_' + count + '" style="height:15px;width:55px;" onchange="loadPIEname(this,' + count + ' );"/>
and a javascript function for doing some function
that works fine.But How to make the function call when i press enter key on that text box? thanks in advance.
I have a text input
<input type="text" name="invCode_' + count + '" style="height:15px;width:55px;" onchange="loadPIEname(this,' + count + ' );"/>
and a javascript function for doing some function
that works fine.But How to make the function call when i press enter key on that text box? thanks in advance.
Share Improve this question asked Aug 12, 2014 at 10:43 user3789344user3789344 811 gold badge3 silver badges14 bronze badges 03 Answers
Reset to default 3<input onkeypress="return myscript(event,this)" ...
Then do
function myscript(e,i){
if(e.keycode == 13){
loadPIEname(i,' + count + ');
}
}
You can use jQuery to do same
$("#id_of_textbox").keyup(function(event){
if(event.keyCode == 13){
$("#id_of_button").click();
}
});
this will work for you.
using plane jave script if u want please use:
<input type="text" id="txtSearch" onkeydown="if (event.keyCode == 13) document.getElementById('btnSearch').click()"/>
Just use onkeypress
instead of onchange
event and check for which key was pressed inside another function like this:
===HTML===
<input type="text" onkeypress="searchKeyPress(event,this,' + count + ' );"/>
===Javascript===
function searchKeyPress(e,args)
{
// look for window.event in case event isn't passed in
if (typeof e == 'undefined' && window.event) { e = window.event; }
if (e.keyCode == 13)
{
loadPIEname(args); //call your function here
}
}
本文标签: javascript function after pressing enter key on text boxStack Overflow
版权声明:本文标题:javascript function after pressing enter key on text box - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742009601a2412638.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论