Last Updated: February 25, 2016
·
1.537K
· 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;
});

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside