get Table cell value

Discussion in 'Javascript' started by Sunny, Oct 20, 2008.

  1. Sunny

    Sunny Guest

    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?
     
    Sunny, Oct 20, 2008
    #1
    1. Advertising

  2. Sunny wrote:

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

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Oct 20, 2008
    #2
    1. Advertising

  3. Sunny

    Sunny Guest

    On Oct 20, 12:02 pm, Martin Honnen <> wrote:
    > Sunny wrote:
    > > <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>
    >
    > --
    >
    > 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.
     
    Sunny, Oct 20, 2008
    #3
  4. 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/
     
    Martin Honnen, Oct 20, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phillip Roncoroni
    Replies:
    14
    Views:
    1,145
    Toby A Inkster
    Apr 5, 2004
  2. =?Utf-8?B?Qw==?=

    Get Table Cell value using Javascript

    =?Utf-8?B?Qw==?=, Apr 23, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    84,143
    oceans_ripple_light
    Jul 25, 2012
  3. =?Utf-8?B?Qw==?=

    Get Table Cell Value using Javascript

    =?Utf-8?B?Qw==?=, Apr 23, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    4,336
    Cowboy \(Gregory A. Beamer\)
    Apr 23, 2007
  4. yukatan

    get a table cell value

    yukatan, Nov 6, 2003, in forum: Javascript
    Replies:
    2
    Views:
    254
    Lasse Reichstein Nielsen
    Nov 6, 2003
  5. harry

    Get 2nd cell value from table row?

    harry, Jul 22, 2004, in forum: Javascript
    Replies:
    2
    Views:
    216
    Mick White
    Jul 22, 2004
Loading...

Share This Page