0

I have this script here that outputs a result from a sql db query but I can not figure out how to get it to put the result in the table cell specified.

Here is query:

<script type="text/javascript">

$(document).ready(function(){
$('.typeval').change(function(){
    var movement =  $(this).val();
    var client_id = $(this).parent().siblings().find('.clientval').val();
    var class_id = <? echo $class_id; ?>;

$.ajax({ 
  type: "POST",
  url: "movement_count.php",
  data: {movement:movement, client_id:client_id, class_id:class_id},
  dataType: "json", 
  success:(function(output) {

      $.each(output, function(index, value){
      alert(value);
      $(".count").append(output[value]);
      }) // each

   }) // success

  }); // ajax

  }); // .typeval

});  // document

</script>   

I want to put the result of this (value):

alert(value);

into here:

<td><label class="count"></label></td>

The <td> I am targeting on the same row as the <select> menu that is triggering the result. There will also be multiple table rows with this exact same cell <td>. So I need to target the <td> on this row only somehow. Can someone help me with this? Im not sure if I need the $.each but my php query is a mysql_fetch_row array even though the value returned will always be just one number.

Here is the HTML markup for the table cell I need the value in:

<td><label class="count"></label></td>

JS source code for class=count:

$(".count").append(output[index]);

ITS WORKING!!!! here is the code below

$(document).ready(function(){
$('.typeval').change(function(){
    var movement    =  $(this).val();
    var client_id   = $(this).parent().siblings().find('.clientval').val();
    var class_id    = <? echo $class_id; ?>;
        $count      = $(this).parents('tr').find('label.count');

$.ajax({ 
  type: "POST",
  url: "movement_count.php",
  data: {movement:movement, client_id:client_id, class_id:class_id},
  dataType: "json", 
  success:(function(output) {

      $.each(output, function(index, value){
      //alert(value);
      $count.append(output[index]);
      }) // each

   }) // success

}); // ajax

}); // .typeval

});  // document
4

2 に答える 2

1

これを交換

$("label.count<?php echo $client_id; ?>").append(output[value]);

$("label.count<?php echo $client_id; ?>").append(value);

またはこれと交互に

$("label.count<?php echo $client_id; ?>").append(output[index]);

これが役立つことを願っています!!

于 2012-09-11T17:19:52.903 に答える
0

作業コード:

$(document).ready(function(){
   $('.typeval').change(function(){
    var movement    =  $(this).val();
    var client_id   = $(this).parent().siblings().find('.clientval').val();
    var class_id    = <? echo $class_id; ?>;
        $count      = $(this).parents('tr').find('label.count');

 $.ajax({ 
  type: "POST",
  url: "movement_count.php",
  data: {movement:movement, client_id:client_id, class_id:class_id},
  dataType: "json", 
  success:(function(output) {

      $.each(output, function(index, value){
      //alert(value);
      $count.append(output[index]);
      }) // each

   }) // success

}); // ajax

}); // .typeval

});  // document
于 2012-09-12T20:28:02.213 に答える