get Table cell value

S

Sunny

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(testObjectId).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?
 
M

Martin Honnen

Sunny said:
<td><a
href="javascript:document.getElementById(testObjectId).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>
 
S

Sunny

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>

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.
 
M

Martin Honnen

Sunny said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top