Reputation: 1411
I am trying to use jQuery to tab to the next cell in a table unsuccessfully and believe this to be due to errors in my selectors. Using developer tools I see that my cells are a span, within a td .EditText, within a <tr>
. Here is the code I'm trying to use.
$(function() {
$('.EditText :text').live("keydown", function(e) {
if (e.which == 9) { //tab Key
$(this).blur();
$(this).parent('tr').next('td #EditText').find('span').click();
return false;
}
});
});
Upvotes: 1
Views: 4158
Reputation: 6586
I decided to take a wack at this also. I've created a jsfiddle for this guy, so check it out and let me know if it looks right.
Here's the js in a nutshell for my current example:
$('table tr td.EditText span input').live('keydown', function(e) {
// get the code of the key that was pressed
var code = e.keyCode ? e.keyCode : e.which;
// varify that the tab key was pressed
if (code === 13) {
// get the next tr's input field, and set focus to it
$(this).parents('tr').next().find('td.EditText span input').focus();
// prevent any default actions
if (e.preventDefault) {
e.preventDefault();
}
return false;
}
});
Upvotes: 0
Reputation: 10077
I believe the line:
$(this).parent('tr').next('td #EditText').find('span').click();
should be:
$(this).next('td.EditText').find('span').focus();
Upvotes: 2
Reputation: 359776
It would be extremely helpful if you could show the actual markup, but I'll take a stab at it:
// Replace this
$(this).blur();
$(this).parent('tr').next('td #EditText').find('span').click();
// With this
$(this).blur().closest('td').next().find('td .EditText span').focus();
Upvotes: 1