piehead Posted February 15, 2013 Share Posted February 15, 2013 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> Quote Link to comment https://forums.phpfreaks.com/topic/274503-help-with-getting-id-from-a-form-in-while-loop-to-my-ajax/ Share on other sites More sharing options...
Jessica Posted February 15, 2013 Share Posted February 15, 2013 Your unique id should be a hidden input field. Quote Link to comment https://forums.phpfreaks.com/topic/274503-help-with-getting-id-from-a-form-in-while-loop-to-my-ajax/#findComment-1412544 Share on other sites More sharing options...
piehead Posted February 15, 2013 Author Share Posted February 15, 2013 How do I pull that in my ajax? Quote Link to comment https://forums.phpfreaks.com/topic/274503-help-with-getting-id-from-a-form-in-while-loop-to-my-ajax/#findComment-1412545 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.