Jump to content

Help with getting ID from a form in While loop to my AJAX


piehead

Recommended Posts

I have been stuck on this for 3 days... I would love the experts to shoot me some words of advice, appreciate it.

 

I have a form I create from a while loop in php. I can submit it if I name the form and place that in the AJAX but it just uploads the last record in the table not the one I actually click. I know I need a unique ID from the form, which I have but I can get it in the AJAX ;( I have used $(this).attr("id") , $(this).form("id") etc and nothing gets it in.. Any advice would be great

 

MY PHP Loop

 

while($row = mysql_fetch_array($pendingresult))

 { 
$id = "myForm".$row['reg_id'];
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0" >';
 print "<form id=\"$id\" name=\"CDs\" method=\"post\" >";

   echo '<tr class="commentContainer" style="color:#FFF">';
   echo"<td><input type=\"text\" name=\"team_name\" value=\"$row[team_name]\"</td>";

   echo"<td><input type=\"text\" name=\"reg_id\" value=\"$id\"</td>";
   echo"<td><input type=\"text\" name=\"team_level\" value=\"$row[team_level]\"</td>";
   echo"<td><input type=\"text\" name=\"notes\" value=\"$row[comments]\"</td>";

   echo"<td>";



echo "<td class=\"delete\" align=\"center\" id=".$row['reg_id']." width=\"10\"><a href=\"#\" id=\"$row[reg_id]\"><img src=\"admin/images/delete.png\" border=\"0\" ></a></td>";
   echo "<td class=\"approve\" align=\"center\" id=".$id." width=\"10\"><a href=\"#\" ><img src=\"admin/images/approve.png\" border=\"0\" ></a></td>";

echo "</td>";

 echo"</tr>";
 echo "</form>";
 echo ' </table>';


 }

 

My AJAX

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>


<script type="text/javascript">
$(document).ready(function() {
<!--$('#load').hide();-->
});


$(function() {
$(".approve").click(function() {
var commentContainer = $(this).parent('tr:first');
var id = $(this).attr("id");
var string = 'id='+ id;
var formData = $(this).attr("id")

$.ajax({
  type: "POST",
  url: "approve.php",
  data: $(formData).serialize(),

  cache: false,
  success: function(){
commentContainer.slideUp('slow', function() {$(this).remove();});

 }

});

return false;
});
});
</script>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.