Reputation: 3841
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
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.
Upvotes: 7