user478636
user478636

Reputation: 3424

event handling in Jquery

I want to know the how to handle when user press up arrow when focused on a textbox

Upvotes: 0

Views: 239

Answers (4)

Arihant Nahata
Arihant Nahata

Reputation: 1810

See this Keypress Event

Upvotes: 1

David
David

Reputation: 219087

You can grab the event itself by binding to the keyup event with jQuery. As for determining which key was pressed, here's a quick little tutorial on key codes in JavaScript. You can adapt this code to check against the key being pressed in the event.

They key code you're looking for (the up arrow) is 38.

Upvotes: 2

locrizak
locrizak

Reputation: 12279


$("input_selector").focus(function(){
    $(this).bind("keyup", function(e){
         if ( e.keyCode == 39){
              //do what you want with the up arrow
         }
    });
});

$("input_selector").blur(function(){
    $(this).unbind("keyup");
});


Upvotes: 1

Quentin
Quentin

Reputation: 944474

See the documentation for keyboard events in jQuery

Upvotes: 1

Related Questions