Reputation: 561
How do I get the index of the current input text field I'm currently in? I'm trying to jump to the next input field after pressing enter. This is what I've got:
var index = $('input:text').index(this);
$('input:text')[nextIndex].focus();
But it's not going to the next one..
Upvotes: 1
Views: 2864
Reputation: 145458
The following code should work fine:
$("input").keypress(function(e) {
if (e.which == 13) {
var index = $("input[type='text']").index(this);
$("input[type='text']").eq(index + 1).focus();
e.preventDefault();
}
});
DEMO: http://jsfiddle.net/uJsMQ/
Upvotes: 1