Last Updated: February 25, 2016
·
1.313K
· purekrome

HTML Input box to fire off some Javascript when the enter key is pressed

Just some simple jQuery code to wire up the 'enter' key on a textbox, which then does some javascript (like an AJAX call to a server).

<input type="text" id="textbox-query" />

$('#textbox-query').keypress(function (e) {
    if (e.which == 13) {
        doSomething(..);
        return false;
    }
    return true;
});