www.webdeveloper.com
Results 1 to 3 of 3

Thread: Target and change specific html table row with jquery.ajax

  1. #1
    Join Date
    Mar 2014
    Posts
    2

    Target and change specific html table row with jquery.ajax

    I have an HTML table generated by PHP querying from MySQL table.

    Code:
        <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:

    Code:
        <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.

  2. #2
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    894
    Maybe I don't understand the problem, but have you tried replacing the alert() line with
    Code:
    $(this).html(response);
    You could also use .text(), but I guess it depends on the specifics of all the data/elements in that table cell.

    [EDIT]
    Actually on second thought, I don't know that the above code will work. If not you could go with
    Code:
    $("#"+thisid).html(response);
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  3. #3
    Join Date
    Mar 2014
    Posts
    2

    @Sup3rkirby - It works. Thanks

    Hey Sup3rkirby:

    Thank you. The second solution works perfectly.

    Thanks again.

    Placid

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles