0

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 ?

2 Answers 2

3

Using jQuery:

$('#someid').keydown(function(event) {
    if (event.keyCode == 10 || event.keyCode == 13) {
        SomeFunctionName();
    }
});
Sign up to request clarification or add additional context in comments.

Comments

0

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

function TextName_OnKeyDown(e)
{		
    var keynum;					
    if(window.event) // IE				
    {
        keynum = e.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which;
    }	
  
    document.getElementById("keynum").innerHTML = keynum;
					
    if (keynum == 13) 
    {
        document.getElementById("keynum").innerHTML += " SearchByName();";
    }
}
<input type="text" ID="TextName" onkeydown="javascript:TextName_OnKeyDown(event)">
<p id="keynum"></p>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.