Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    16
    Thanks
    4
    Thanked 0 Times in 0 Posts

    How do I associate an ID with a content of a div?

    Hi

    For example I have a HTML table...

    Code:
    name | grade  | action
    bob  | 1.0    | [button class="button" id='1']
    jack | 2.0    | [button class="button" id='2']
    john | 3.0    | [button class="button" id='3']
    When I click the button,

    to get the id...

    Code:
    $(function(){
    $('.button').click(function()
    var buttonid = this.id
    });
    });
    so if I were to press buttonid 1 how do I get the grade '1.0' without having to open the database?

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    please show the exact html structure you are using.

  • #3
    New Coder
    Join Date
    Sep 2011
    Posts
    16
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DanInMa View Post
    please show the exact html structure you are using.
    Im using PHP while loop to create the table


    Code:
    $(function(){
    $('.button').click(function()
    var buttonid = this.id
    });
    });
    <table>
    <tr>
    <th>NAME</th>
    <th>GRADE</th>
    <th>ACTION</th>
    </tr>
    <?php
    //ACCESS DB
    while(){ //MYSQL FETCH ASSOC STATEMENT
    echo '<tr>'; 
    echo '<td>'.$name.'</td>'; 
    echo '<td>'.$grade.'</td>'; 
    echo '<td> <input type="button" class="button" id="'.$id'"</td>';
    echo '</tr>';
    }
    ?>
    </table>

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    For the beginning: the id can not start with a digit. W3C recommendation:

    "ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".")."
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •