Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > get Table cell value

Reply
Thread Tools

get Table cell value

 
 
Sunny
Guest
Posts: n/a
 
      10-20-2008
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?
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      10-20-2008
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/
 
Reply With Quote
 
 
 
 
Sunny
Guest
Posts: n/a
 
      10-20-2008
On Oct 20, 12:02 pm, Martin Honnen <(E-Mail Removed)> wrote:
> 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.
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      10-20-2008
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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get Table Cell value using Javascript =?Utf-8?B?Qw==?= ASP .Net 5 07-25-2012 02:45 PM
Get Table Cell Value using Javascript =?Utf-8?B?Qw==?= ASP .Net 1 04-23-2007 01:10 PM
Get 2nd cell value from table row? harry Javascript 2 07-22-2004 01:34 PM
How do I have a table cell fetch another page to display within the cell? Phillip Roncoroni HTML 14 04-05-2004 05:58 PM
get a table cell value yukatan Javascript 2 11-06-2003 11:52 PM



Advertisments