By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,831 Members | 1,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,831 IT Pros & Developers. It's quick & easy.

get Table cell value

P: n/a
Hi,

If I have an Html like that:
<input id="testObjectId" type="text" value="1" />
<table>
<tr>
<td>25</td>
<td>Sunday</td>
<td>0</td>
<td>518</td>
</tr>
</table>

How Can I use "a href" to put value in the Textbox by clicking on
table cell.
somehing like:
<td><a
href="javascript:document.getElementById(testObjec tId).value='25'>25</
a></td>
Should work:
But this is writing on the screen in a new window instead of a
Textbox.

What to do?
Oct 20 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Sunny wrote:
<td><a
href="javascript:document.getElementById(testObjec tId).value='25'>25</
a></td>
Put the code in an onclick handler
<td onclick="document.getElementById('someId').value =
this.firstChild.nodeValue;">25</td>
or if you need the link
<td><a href="#" onclick="document.getElementById('someId').value =
this.firstChild.nodeValue; return false;">25</a></td>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 20 '08 #2

P: n/a
On Oct 20, 12:02 pm, Martin Honnen <mahotr...@yahoo.dewrote:
Sunny wrote:
<td><a
href="javascript:document.getElementById(testObjec tId).value='25'>25</
a></td>

Put the code in an onclick handler
<td onclick="document.getElementById('someId').value =
this.firstChild.nodeValue;">25</td>
or if you need the link
<td><a href="#" onclick="document.getElementById('someId').value =
this.firstChild.nodeValue; return false;">25</a></td>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Thanks martin It works.
<table>
<tr>
<td>25</td>
<td>Sunday</td>
<td>0</td>
<td>518</td>
</tr>
</table>
But what if, I want to put a href on Sunday & Want to display 25 in
textbox on click.
Oct 20 '08 #3

P: n/a
Sunny wrote:
But what if, I want to put a href on Sunday & Want to display 25 in
textbox on click.
Well then assign the string literal '25' as you had in your original
code. Or get fancy with

<table>
<tr>
<td>25</td>
<td onclick="document.getElementById('someId').value =
this.parentNode.cells[this.cellIndex - 1].firstChild.nodeValue;">Sunday</td>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 20 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.