469,323 Members | 1,235 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

get Table cell value

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
3 5679
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
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
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.

Similar topics

2 posts views Thread by Seth | last post: by
1 post views Thread by Thanks | last post: by
7 posts views Thread by slitvinov | last post: by
7 posts views Thread by Kamal | last post: by
5 posts views Thread by jrod11 | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.