moteutsch
moteutsch

Reputation: 3841

How to stop cursor from jumping to beginning/end of textbox on up/down key?

How can I prevent the cursor from jumping to the beginning or end of a textbox when up or down arrow key is pressed, using JavaScript and jQuery?

Upvotes: 2

Views: 3949

Answers (1)

Joseph Marikle
Joseph Marikle

Reputation: 78550

<input type="text" />


$("input:text").keydown(function(e){
   if(e.which == 38 || e.which == 40) 
       e.preventDefault();
});

You can prevent default on the up and down arrow keys.

http://jsfiddle.net/C5ZCE/

Upvotes: 7

Related Questions