GKChesterton
Programmer
I am making a chekerboard. The user can set the pieces on the board and submit her arrangement using an HTML form.
This calls for a form that includes an 8x8 table. Each cell allows the user to indicate Red, Black or (default) Empty.
Now I reach for JavaScript, because I'd like the option selection for each cell to happen by clicking. Go to the cell and click 1 for Red; click 2 for Black, click 3 to return to Empty. (Maybe you call this a three-state button.)
I have some script code that works great for setting a value and changing the background color upon mouse-click. Excerpt:
However, I don’t want to change the background color; I want to change an image (red_piece.gif, black_piece.gif, blank.gif).
Also I’m not sure how to pass the value as an option selection when the form is submitted. Can you instruct me?
This calls for a form that includes an 8x8 table. Each cell allows the user to indicate Red, Black or (default) Empty.
Now I reach for JavaScript, because I'd like the option selection for each cell to happen by clicking. Go to the cell and click 1 for Red; click 2 for Black, click 3 to return to Empty. (Maybe you call this a three-state button.)
I have some script code that works great for setting a value and changing the background color upon mouse-click. Excerpt:
Code:
function changeCellValue()
{
var index = getNextIndex(this.firstChild.data);
cIndex = cells.indexOf(this);
applyChanges(index, cIndex);
}
function applyChanges(index, cIndex)
{
cells[cIndex].firstChild.data = values[index];
cells[cIndex].style.backgroundColor = bgColors[index];
cellValues[cIndex] = values[index];
}
However, I don’t want to change the background color; I want to change an image (red_piece.gif, black_piece.gif, blank.gif).
Also I’m not sure how to pass the value as an option selection when the form is submitted. Can you instruct me?