...

View Full Version : Moving cell with arrow buttons



Painfall
01-05-2011, 04:35 PM
Hello. I want to move something with the arrow keys, but some aprt of script is incorrect and it's not working


</style>

<script type="text/javascript">
function setup() {
row=0;
col=0;
imageSnake(row,col);
}
</script>


</head>

<body onload="setup()" onkeydown="handleKey(event)">
<center>
<script type="text/JavaScript">


document.write('<table border="1" cellspacing="0" cellpadding="10">')
var count =0

for (var row=0; row<20; row++) {
document.write('<tr>');
for (var col=0; col<20; col++) {

document.write('<td style="border:0"; id="count++";>');

document.write('</td>');

}
document.write('</tr>');


}

function handleKey(e) {

if (e.type == 'keydown' && (e.keyCode == 27 || (e.keyCode >= 37 && e.keyCode <= 40))) {

switch(e.keyCode) {
case 37:
dC = -1;
dR = 0;
break;
}

emptyCell(row,col);

function emptyCell
var id = 'r' + r + 'c' + c;
var cell = document.getElementById(id);
if (cell) cell.innerHTML='';
}

row += dR
col += dC

function insertImage(r,c) {
var id = 'r' + r + 'c' + c;
var cell = document.getElementById(id);
var color = cell.className;

if (color != 'white') {
var image = 'img.gif';
}else{
var image = 'img2.gif';
}
cell.innerHTML = '<img src="" + image + alt="" + color + 'image' />';
}

</script>

Thank you for any noticed error.

Painfall
01-05-2011, 06:30 PM
Anyone?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum