...

View Full Version : How do I associate an ID with a content of a div?



JustBob
10-11-2011, 11:55 AM
Hi

For example I have a HTML table...


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


$(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?

DanInMa
10-11-2011, 11:58 AM
please show the exact html structure you are using.

JustBob
10-11-2011, 12:09 PM
please show the exact html structure you are using.

Im using PHP while loop to create the table




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

Kor
10-11-2011, 12:16 PM
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 (".")."



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum