jQuery capture ‘Enter’ key in text field

Fiddle
http://jsfiddle.net/pootie/8wGFe/2/

Code

$(document).ready(function() {
    $('#searchBox').keypress(function(event){
        var keycode = (event.keyCode ? event.keyCode : event.which);
        if(keycode == '13'){
            alert('You pressed a "enter" key in textbox');    
        }
    });
}

admin

Chris Grgich-Tran is a Development Manager from Brisbane, Australia. When he's not dad-ing it up, he works with some very talented people.

More Posts

Follow Me:
TwitterFacebookLinkedInGoogle PlusFlickrYouTube

Comments