Get data into a table cell

Discussion in 'JavaScript' started by Ivanzinho, Feb 29, 2008.

  1. #1
    Hello, I guess this is easy, I am working with PHP and MySQL, and I build a table with result of a sql query, the table strutcture is:

    
    <table>
    <tr><td>ID</td><td>Name</td><td>E-mail</td><td>
    <?php
    include 'config.php';
    include 'opendb.php';
    $query= 'select * from customers.contact';
    $result = mysql_query($query);
    while($row = mysql_fetch_array($result)){
    echo "<tr><td>", $row['cid'],"</td>".
    "<td>", $row['cname'],"</td>".
    "<td>", $row['csubject'], "</td></tr>";
    }
    include 'closedb.php';
    ?>
    
    Code (markup):
    And you now, return a table with 3 fields and the database information, now, I want to do, for example, click over the table cell ID number 35, and when I do click, javascript return the value 35, this is for update and delete scripts, but I don't know how to get the value into a that cell or another cells, ¿how do I can get it?

    Thank you for the help
     
    Ivanzinho, Feb 29, 2008 IP
  2. Morishani

    Morishani Peon

    Messages:
    239
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can reach the TR element from the TD element by using this.parentNode (this = td you clicked on it), and then go to the first cell by using .childNodes[0].innerText

    I hope it is enough explained. if you need further help - respond.
     
    Morishani, Mar 1, 2008 IP
  3. lephron

    lephron Active Member

    Messages:
    204
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    You've got the ID when you generate the page, so you can dynamically create the JS too with the required id. There shouldn't be any need for DOM traversal
     
    lephron, Mar 2, 2008 IP