Placid 1 Posted March 6, 2014 Report Share Posted March 6, 2014 I have an HTML table generated by PHP querying from MySQL table. <table> <tr> <th>Sl</th> <th>ID</th> <th>Article Name</th> <th>Publish Status</th> </tr> <?php $i = 1; foreach ($obj->showAllFromTable('pattern') as $pattern) { extract($pattern); ?> <tr> <td><?php echo $i++; ?></td> <td><?php echo $id; ?></td> <td><?php echo $pattern_name; ?></td> <td id="publish_<?php echo $id; ?>" class="status_pattern"> <?php echo $publish; ?> </td> </tr> <?php } ?> </table>I want to change the status of any article by clicking on the 'publish' cell of the corresponding article row. I am trying to use ajax method of jquery for this purpose as shown in the following: <script type="text/javascript"> $(document).ready(function(){ $('.status_pattern').click(function(){ var thisid = $(this).attr('id'); $.ajax({ url: "status_change_pattern.php", data: { id: thisid }, success: function (response) { alert(response); } }); }); }); </script>In the "success" block, instead of "alert", I want to create a functionality to change the text of the specific cell which I clicked. The "status_change_pattern.php" has just a text "Hey Hey".Can anyone help? Please.Thanks. Quote Link to post Share on other sites
HartleySan 826 Posted March 6, 2014 Report Share Posted March 6, 2014 Assuming you're just returning a string from the PHP script: $(thisid).html(response); Quote Link to post Share on other sites
Placid 1 Posted March 7, 2014 Author Report Share Posted March 7, 2014 Hey Hartley San, I'm sure you don't remember me. But you were my savior in the past... Thanks for your kind response. I have found the following to be a perfect solution: $('#'+thisid).html(response); Got the above from forum.jquery.com. Thanks again. 1 Quote Link to post Share on other sites
HartleySan 826 Posted March 7, 2014 Report Share Posted March 7, 2014 Yes, you're right. We definitely need the '#' in there. Good save. I guess that's a good reason to always test out code before you recommend it to someone else. Thanks. Quote Link to post Share on other sites
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.
Note: Your post will require moderator approval before it will be visible.