get Table cell value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sunny

    get Table cell value

    Hi,

    If I have an Html like that:
    <input id="testObjectI d" 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="javascrip t:document.getE lementById(test ObjectId).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?
  • Martin Honnen

    #2
    Re: get Table cell value

    Sunny wrote:
    <td><a
    href="javascrip t:document.getE lementById(test ObjectId).value ='25'>25</
    a></td>
    Put the code in an onclick handler
    <td onclick="docume nt.getElementBy Id('someId').va lue =
    this.firstChild .nodeValue;">25 </td>
    or if you need the link
    <td><a href="#" onclick="docume nt.getElementBy Id('someId').va lue =
    this.firstChild .nodeValue; return false;">25</a></td>

    --

    Martin Honnen

    Comment

    • Sunny

      #3
      Re: get Table cell value

      On Oct 20, 12:02 pm, Martin Honnen <mahotr...@yaho o.dewrote:
      Sunny wrote:
      <td><a
      href="javascrip t:document.getE lementById(test ObjectId).value ='25'>25</
      a></td>
      >
      Put the code in an onclick handler
      <td onclick="docume nt.getElementBy Id('someId').va lue =
      this.firstChild .nodeValue;">25 </td>
      or if you need the link
      <td><a href="#" onclick="docume nt.getElementBy Id('someId').va lue =
      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.

      Comment

      • Martin Honnen

        #4
        Re: get Table cell value

        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="docume nt.getElementBy Id('someId').va lue =
        this.parentNode .cells[this.cellIndex - 1].firstChild.nod eValue;">Sunday </td>

        --

        Martin Honnen

        Comment

        Working...