Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Moving cell with arrow buttons

    Hello. I want to move something with the arrow keys, but some aprt of script is incorrect and it's not working
    Code:
    </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.
    Last edited by Painfall; 01-05-2011 at 04:52 PM.

  • #2
    New Coder
    Join Date
    Dec 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •