tags:

views:

766

answers:

2

I have an ASP.NET page with some text boxes meant for searching purpose.Now i want to invoke a javascript function which is already written ,when the user press the enter key.I am having jQuery in my page. Any easy ways to do this ?

+1  A: 

Using jQuery:

$('#someid').keydown(function(event) {
    if (event.keyCode == 10 || event.keyCode == 13) {
        SomeFunctionName();
    }
});
JonoW
A: 

I would add the onkeydown attribute to the text box and apply the function like this example.

    <input type="text" ID="TextName" onkeydown="javascript:TextName_OnKeyDown(event)">

              function TextName_OnKeyDown(e)
                {    
                    var keynum     
                    if(window.event) // IE    
                    {
                     keynum = e.keyCode
                    }
                    else if(e.which) // Netscape/Firefox/Opera
                    {
                     keynum = e.which
                    }   

                    if (keynum == 13) 
                    {
                     SearchByName()
                    }
                }
Avitus