Depending on where the user clicks on the field, there must be a cross or a zero. Here I try to make a cross ( 40px - длина стороны 1 квадрата ). The coordinates of the square are xQwad and yQwad .
function select() { // обработка нажатия на поле //alert(event.offsetX + 'x' + event.offsetY); var crossOrNo = localStorage["crossOrNo"], field = localStorage["field"], xQwad = (event.offsetX / 40) - ((event.offsetX / 40) % 1), yQwad = (event.offsetY / 40) - ((event.offsetY / 40) % 1); field[xQwad][yQwad] = crossOrNo; localStorage["field"] = field; if (crossOrNo == 1) { var img = new Image(); img.src = "cross.png"; img.width = 40; img.height = 40; document.getElementById("fieldOnWeb").innerHTML = "<img src='cross.png' style='height: 40px; width: 40px;' />"; localStorage["crossOrNo"] = 0; } else if (crossOrNo == 0) localStorage["crossOrNo"] == 1; //alert(xQwad + 'x' + yQwad); }