Puoi provare questo
codice:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<style type="text/css">
<!--
.protected {background-color:#006666}
.unprotected {background-color:yellow}
.button {width:70}
-->
</style>
<script language="JavaScript" type="text/javascript">
<!--
var maxRows = 3;
var maxCols = 5;
var startRow = 1;
var startCol = 1;
var previous = null;
function move(direction) {
switch (direction) {
case "up" :
if (startRow - 1 >= 1) {
move2(startCol, startRow - 1);
} // if (startRow - 1 >= 1
break;
case "down" :
if (startRow + 1 <= maxRows) {
move2(startCol, startRow + 1);
} // if (startRow + 1 <= maxRows)
break;
case "left" :
if (startCol - 1 >= 1) {
move2(startCol - 1,startRow);
} // if (startCol - 1 >= 1)
break;
case "right" :
if (startCol + 1 <= maxCols) {
move2(startCol + 1,startRow);
} // if (startCol + 1 <= maxCols)
break;
} // switch (direction)
} // function move(direction)
function move2(col,row) {
//------- Settaggio dell'id dell'input corrente
inputId = "input("+row+","+col+")";
//------- Ripristino proprieta dell'input precedente
if (previous != null) {
previous.className = "protected";
previous.readOnly = true;
} // if (previous != null)
//------- Settaggio propieta input corrente
document.getElementById(inputId).className = "unprotected";
document.getElementById(inputId).readOnly = false;
document.getElementById(inputId).focus();
//------- Input precedente = input corrente
previous = document.getElementById(inputId);
//------- Coordinate dell'input corrente
startRow = row;
startCol = col;
} // function move2(col,row)
//-->
</script>
</head>
<body>
<table summary="" border="1">
<tr>
<td id="cell(1,1)"><input id="input(1,1)" type="text" class="protected" readonly size="15"></td>
<td id="cell(1,2)"><input id="input(1,2)" type="text" class="protected" readonly size="15"></td>
<td id="cell(1,3)"><input id="input(1,3)" type="text" class="protected" readonly size="15"></td>
<td id="cell(1,4)"><input id="input(1,4)" type="text" class="protected" readonly size="15"></td>
<td id="cell(1,5)"><input id="input(1,5)" type="text" class="protected" readonly size="15"></td>
</tr>
<tr>
<td id="cell(2,1)"><input id="input(2,1)" type="text" class="protected" readonly size="15"></td>
<td id="cell(2,2)"><input id="input(2,2)" type="text" class="protected" readonly size="15"></td>
<td id="cell(2,3)"><input id="input(2,3)" type="text" class="protected" readonly size="15"></td>
<td id="cell(2,4)"><input id="input(2,4)" type="text" class="protected" readonly size="15"></td>
<td id="cell(2,5)"><input id="input(2,5)" type="text" class="protected" readonly size="15"></td>
</tr>
<tr>
<td id="cell(3,1)"><input id="input(3,1)" type="text" class="protected" readonly size="15"></td>
<td id="cell(3,2)"><input id="input(3,2)" type="text" class="protected" readonly size="15"></td>
<td id="cell(3,3)"><input id="input(3,3)" type="text" class="protected" readonly size="15"></td>
<td id="cell(3,4)"><input id="input(3,4)" type="text" class="protected" readonly size="15"></td>
<td id="cell(3,5)"><input id="input(3,5)" type="text" class="protected" readonly size="15"></td>
</tr>
</table>
<table summary="">
<tr>
<td></td>
<td><input class="button" type="button" value="Up" onclick="move('up')"></td>
<td></td>
</tr>
<tr>
<td><input class="button" type="button" value="Left" onclick="move('left')"></td>
<td></td>
<td><input class="button" type="button" value="Right" onclick="move('right')"></td>
</tr>
<tr>
<td></td>
<td><input class="button" type="button" value="Down" onclick="move('down')"></td>
<td></td>
</tr>
</table>
<script language="JavaScript" type="text/javascript">
<!--
move2(startCol,startRow)
//-->
</script>
</body>
</html>