You should be able to focus the various cells, I will put an example together using .focus()
Here is the example.
Please bear in mind that...
a) There is nothing in this example to stop you from going out of bounds, you would need to restrict the values of currentRow and currentCell to the number of cells and prevent them from going below 0.
b) At the moment, there is no code to remove the green text, which is what I've used to show the current focus. This means a green trail is left behind.
You could solve both of the above fairly easily, but they would make the example more complicated...
var currentRow = 0;
var currentCell = 0;
function ChangeCurrentCell() {
var tableRow = document.getElementsByTagName("tr")[currentRow];
var tableCell = tableRow.childNodes[currentCell];
tableCell.focus();
tableCell.style.color = "Green";
}
ChangeCurrentCell();
$(document).keydown(function(e){
if (e.keyCode == 37) {
currentCell--;
ChangeCurrentCell();
return false;
}
if (e.keyCode == 38) {
currentRow--;
ChangeCurrentCell();
return false;
}
if (e.keyCode == 39) {
currentCell++;
ChangeCurrentCell();
return false;
}
if (e.keyCode == 40) {
currentRow++;
ChangeCurrentCell();
return false;
}
});
Sohnee
2010-07-14 10:55:30