
Hi all,
I am new to JSP/Servlet .Please help. I need to send the table cell index in servlet using javascript and should be able to make a cell index to have a text - "X" / "0"only once.
Here is my code sofar-
function editTableCell(e)
{
var player1=true;
var player2=true;
var CellText = null;
alert(e);
var SelectedElement = document.getElementById(e);
alert(SelectedElement);
if(player1)
{
//e.innerHTML="X";
SelectedElement.innerHTML = "X";
//CellText = SelectedElement.innerHTML;
}
else{
SelectedElement = e;
e.innerHTML = "0";
CellText = e.innerHTML;
}
}
</script>
<style type="text/css">
body{
text-align: center;
}
table{
text-align: center;
table-layout:fixed;
}
</style>
</head>
<body>
<div>
<form method="post" action="TicTacToeGame">
<table id="board" border=1 align=center cellpadding="2" cellspacing="3" width="250" height="250" >
<tr>
<td id="1" onClick="editTableCell(1)"></td>
<td id="2" onClick="editTableCell(2)"></td>
<td id="3" onClick="editTableCell(3)"> </td>
</tr>
<tr>
<td id="4" onClick="editTableCell(4)"></td>
<td id="5" onClick="editTableCell(5)"></td>
<td id="6" onClick="editTableCell(6)"> </td>
</tr>
<tr>
<td id="7" onClick="editTableCell(7)"></td>
<td id="8" onClick="editTableCell(8)"></td>
<td id="9" onClick="editTableCell(9)"> </td>
</table>
<div><input type="submit" value="Move" name="Submit"></div>
</form>
</div>
</body>
</html>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.