moosey_man1988 Posted November 3, 2015 Share Posted November 3, 2015 Hi Everyone I'm having some troubles (again) with jquery, I have a table which is created by a while loop which loops out this info here: //Contains a hidden input so we can submit a deletion of the receipt echo "<tr><td>".$receiptName."</td><td>".$receiptNote."</td><td>£".$receiptValue."</td><td>".$receiptDate."</td><td> <a href=".$url . $receiptPath . $receiptFile."><img class='zoom-image' style='width:auto;' src=".$url . $receiptPath . $justfileName.".jpg></img></a></td> <td class='hidden'><input id='ReceiptId' class='hidden' name='FileID' value='".$fileId."'></td> <td><a type='submit' href='#' OnClick='removeReceipt()'><h1 class='glyphicon glyphicon-remove-circle' style='opacity: 0.25;'></td></tr>"; } else { //Contains a hidden input so we can submit a deletion of the receipt echo "<tr><td>".$receiptName."</td><td>".$receiptNote."</td><td>£".$receiptValue."</td><td>".$receiptDate."</td><td> <a href=".$url . $receiptPath . $receiptFile."><img class='zoom-image' style='width:auto;' src=".$url . $receiptPath . $receiptFile."></img></a></td> <input id='ReceiptId' class='hidden' name='FileID' value='".$fileId."'> <td><a type='submit' href='#' class='btn' OnClick='removeReceipt()'><h1 class='glyphicon glyphicon-remove-circle' style='opacity: 0.25;'></td></tr>"; and my Jquery is <script type="text/javascript"> function removeReceipt() { $.ajax({ url: '<?php echo Thisurl();?>', data:{ReceiptId: $('#ReceiptId').val() }, type: 'post', success:function() { window.location.reload(true); } }); } </script> But I just realized this will only delete the top item on the list because ReceiptId Is exactly the same on every row so it just chooses the first one and deletes it. Is there a way I can do something like? OnClick='removeReceipt(".<?php echo $fileId.") and have the javascript function read that variable? e.g It would be something like OnClick='removeReceipt(32)' the Javascript function can then take that 32 a supply it to the rest of the php from below <?php //This will call the remove receipt function if called by the ajax form above. if (isset($_POST['ReceiptId'])){ $receiptId = $_POST['ReceiptId']; removeTheReceipt($receiptId); } ?> Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted November 3, 2015 Solution Share Posted November 3, 2015 Yes you can echo the value of $fileId for passing its as an argument to the javascript function. Your javascript function definition then becomes function removeReceipt(fileId) { $.ajax({ url: '<?php echo Thisurl();?>', data:{ReceiptId: fileId }, type: 'post', success:function() { window.location.reload(true); } }); } Quote Link to comment Share on other sites More sharing options...
moosey_man1988 Posted November 3, 2015 Author Share Posted November 3, 2015 You literally just responded after i head banged a bit and figured it out, I'm having massive trouble with getting my head around javascript.... Maybe I A training course is required its about £2500 though :| Thanks for the response Ch0cu3rI really appreciate all the help I get on this site. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 3, 2015 Share Posted November 3, 2015 Maybe I A training course is required its about £2500 though :| What? Or free if you use google. Quote Link to comment 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.