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 0
Add a ment  | 

3 Answers 3

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