0

Wayne's code worked, thanks for that. Now I'm running into an issue where a URL parameter is passed in through a PHP loop. Once the link is clicked, the code loops through a bunch of user IDs and rather than echoing the row that was clicked, it continues to loop through all of the user IDs.

Before it echoed an ID that corresponded to the rest of the data in the cell.

<?php while ($row = mysql_fetch_assoc($result)) : ?>
<?php $id = $row['id']; 


<script type="text/javascript">
jQuery(document).ready(function(){
$(".userDetailsLink").click(function() {
  $.ajax({
   url: "userdetail.php?id=<?php echo $id ?>",
   success: function(msg){
     $("#results").html(msg);
   }
 });
});
 });
</script>



   <td width="90px" class="resultsDisplay"><a class="userDetailsLink"> <?php echo $row['Username']; ?></a></td>
user547794
  • 14,263
  • 36
  • 103
  • 152

1 Answers1

0
<a id="button" href="#" ... add any custom tags that contain info ...>this is a link</a>

Your jQuery fires when any element with the id tag equal to button is clicked.

You could change that from $("#button").click(function() to $("#myajax").click(function() because of the semantics of having a link have an id of button, and use id="myajax" instead.

Wayne
  • 4,760
  • 1
  • 24
  • 24
  • also, if you have multiple links with the same id, that is invalid mark up. each id on your page needs to be unique. you should use classes to identify these buttons instead. – dqhendricks Jan 01 '11 at 01:01
  • True if there is more than one element it should be a class. That would start looking like http://stackoverflow.com/questions/3272384/how-to-code-one-jquery-function-for-all-ajax-links – Wayne Jan 01 '11 at 01:22