...

View Full Version : jQuery: Fetch Button Value.



phantom007
09-09-2008, 07:58 AM
ok, Let me be as simple as I can with my question.

I have an index.php page.



<HTML>
<head>
<TITLE>Welcome</TITLE>
<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function(){
$("#populate_tables").load("ajax.php?id=10");
});
</script>
</head>


<div id="populate_tables"></div>

</html>


The index.php loads all the information in the <div id="populate_tables"></div> tag when the page loads. This part works fine.


Now, Lets see the code for ajax.php



<?php $id =$_GET['id'];
$attachments = mysql_query("select * from tbl where id=$id order by id desc");
$num_rows = count($attachments);
?>
<table width="50%" border="1" cellspacing="0" cellpadding="3" class="border" style="border-collapse:collapse">
<?php
if($num_rows>0){
for($x=0;$x<$num_rows;$x++){?>
<tr>
<td><input type="submit" id="att_del" name="att_del" value="<?php echo $attachments[$x]['id'];?>" /></td>
</tr>
<?php }//end for loop
}else{//ifelse condition
?>
<tr>
<td align="center">No Attachments</td>
</tr>
<?php
}//end else
?>
</table>


Everything works well so far.

Lets go back to the index.php page :)

When the list loads under the <div id="populate_tables"></div> tag, and when I click on the buttons (att_del), it should alert me with their button value.

Please help.


Thanx

shyam
09-09-2008, 08:24 AM
add a callback

<HTML>
<head>
<TITLE>Welcome</TITLE>
<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function(){
$("#populate_tables").load("ajax.php?id=10", '', function() {
$('#att_del').click(function() { alert($(this).value); });
});
</script>
</head>


<div id="populate_tables"></div>

</html>

phantom007
09-09-2008, 08:54 AM
Hey,


This works only for the first item in the table. Button # 8 in this case and Not for others :(


The output would be something like

http://img504.imageshack.us/img504/7888/220943354848rc7.png





Any idea why?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum