Answer the question
In order to leave comments, you need to log in
How to update the checkerboard without reloading the page?
Good afternoon, I need help from those who understand js, I myself am not strong in it.
I'm trying to write a game like online checkers / chess, I took one of the options found on the Internet as a js code sample.
There is an array of fields:
var board;
Board(1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,-1,0,-1,0,-1,0,-1,-1,0,-1,0,-1,0,-1,0,0,-1,0,-1,0,-1,0,-1);
var square_dim = 45;
document.write("<table border=0 cellspacing=0 cellpadding=0 width="+(square_dim*8+8)
+"<tr><td><img src='black.gif' width="+(square_dim*8+8)
+" height=4><br></td></tr>");
for(var j=0;j<8;j++) {
document.write("<tr><td><img src='black.gif' width=4 height="+square_dim+">");
for(var i=0;i<8;i++) {
if (moveable_space(i,j))
document.write("<a href='javascript:clicked("+i+","+j+")'>");
document.write("<img src='");
if (board[i][j]==1) document.write("you1.gif");
else if (board[i][j]==-1) document.write("me1.gif");
else if (moveable_space(i,j)) document.write("gray.gif");
else document.write("black.gif");
document.write("' width="+square_dim+" height="+square_dim
+" name='space"+i+""+j+"' border=0>");
if (moveable_space(i,j)) document.write("</a>");}
document.write("<img src='black.gif' width=4 height="+square_dim+"></td></tr>");}
document.write("<tr><td><img src='black.gif' width="+(square_dim*8+8)
+" height=4><br></td></tr></table><br>"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question