This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Fetching one table cell click and passing it to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Fetching one table cell click and passing it to servlet" Watch "Fetching one table cell click and passing it to servlet" New topic
Author

Fetching one table cell click and passing it to servlet

Navya J Nair
Greenhorn

Joined: Apr 04, 2012
Posts: 15
Hi All,

Please help !!!

I am building a TicTacToe game web-services application using jsp and servlet where I need to extract the table's cell onclick event each time for each user and pass is to servlet.

The code so far I have built is :

</script>
<style type="text/css">
body{
text-align: center;
}
table{
text-align: center;
table-layout:fixed;
}
</style>
</head>

<body>
<form action="TicTacToeGame" method="post">

<table id="board" border=1 align=left cellpadding="2" cellspacing="3" width="250" height="250" >
<tr>
<td> <input type="button" name="11" /> </td>
<td> <input type="button" name="12" /> </td>
<td> <input type="button" name="13" /> </td>
</tr>
<tr>
<td> <input type="button" name="21" /> </td>
<td> <input type="button" name="22" /> </td>
<td> <input type="button" name="23" /> </td>
</tr>
<tr>
<td> <input type="button" name="31" /> </td>
<td> <input type="button" name="32" /> </td>
<td> <input type="button" name="33" /> </td>
</table>
<div>
<input type="submit" name="submit" value="MyMove">
</div>

</form>
</body>

</html>
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Navya J Nair wrote:I need to extract the table's cell onclick event each time for each user and pass is to servlet.


In other words, you need to do something with Javascript but you don't know exactly what. That doesn't make it a question about Servlets, it makes it a question about Javascript. Which we have a forum for, so let's move the post over there.
Navya J Nair
Greenhorn

Joined: Apr 04, 2012
Posts: 15
Sorry about that.Yes I need to fetch using javascript of table cell's click at a single time for one player.Please help.I am stuck up with this.
Navya J Nair
Greenhorn

Joined: Apr 04, 2012
Posts: 15
Hi All,

I am building a TicTacToe game web-services application using jsp and servlet where I need to extract the table's cell onclick event each time for each user and pass is to servlet using javascript

The code so far I have built is :


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

And so those <input> elements are what you're calling "table cells"? Is your question how to add "onclick" attributes to those elements, or what?
Navya J Nair
Greenhorn

Joined: Apr 04, 2012
Posts: 15
Thanks for all the replies.
Actually I have a ques regarding the table cell.Can we make use of only table <td> and have onclick event on that. or should have to use any input type like button.
And at a time we need to make use of 1 click on 1 button .So how can we make fetch the cell events in javascript
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

If your question was "Does the <td> tag support the onclick attribute?" then let me just point out that any basic HTML resource should tell you that. I would strongly recommend that you find one: you'll find it much easier if you just look it up rather than waiting for hours just to find one simple answer.
Navya J Nair
Greenhorn

Joined: Apr 04, 2012
Posts: 15
I am looking but its quite complicated as we need to find only one onclick event at a time of 1 player.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I don't see why that makes it complicated. When the user clicks on something which has an onclick attribute, you get an onclick event. The user can only click on one thing at a time, so you can only get one onclick event at a time.
Navya J Nair
Greenhorn

Joined: Apr 04, 2012
Posts: 15

This is Tictactoe game-
my concern is when user clicks/make move on button it should write a content and it needs to be saved in database and then it has to again fetched back from db when 2nd player is ready for placing his mark/move on other button it

hope you got it
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Fetching one table cell click and passing it to servlet
 
Similar Threads
how show values in jsp from getting database
How to getParameter value
Fetching one table cell click and passing it to servlet
How can i get selected radio button value using jsp
Doubts in jsp