1

This is development of my question in : stackoverflow. This is the screenchot of my app : Screenshoot

Please see, I have a dropdown list in first column (item), when selected, I will update the third column like this

$.get("/index.php?r=kasir%2Ftransaction%2Fget-price-item&id=" +$(this).val(), function(data){
    $(this).closest("tr").find(".harga-jual").val(data.price.harga)
    });

My goal is, I want to set value the harga's column on row itself. So, in select option at first row selected, harga's updated just in first column, next in second so on...

How can I selected this on jquery ?

Thanks.

2
  • Can you try without encoding.. /index.php?r=kasir/transaction/get-price-item&id= , check if the ajax call is successful, check the data from ajax is as expected.. Commented Nov 1, 2016 at 16:13
  • Yes, the ajax is working, I have debug it with console.log(data). I dont kow to select the html element that I want to as aabove. Commented Nov 1, 2016 at 18:02

2 Answers 2

1

I guess the problem is with $(this) in $.get(). Save the $(this) reference outside of the ajax call and try to use in ajax as code below

$("item1").on('change', function() {
   var $this = $(this);
   $.get("/index.php?r=kasir%2Ftransaction%2Fget-price-item&id="   +$(this).val(), function(data){
    console.log("harga:"+ $this.closest("tr").find(".harga-jual").length);
    $this.closest("tr").find(".harga-jual").val(data.price.harga)
   });
});
Sign up to request clarification or add additional context in comments.

Comments

0

Thanks for user3498863,

Now code it successfully works like this : in yii way :

 <?=
                                    $form->field($modelTools, "[{$indexTools}]item_id")->label(false)->dropDownList(ArrayHelper::map(ItemLayanan::find()->all(), 'id', 'nama_item'), ['prompt' => 'Select item',
                                        'class' => 'item_id',
                                        'onchange' => ''
                                        . 'var $this = $(this);'
                                        . 'var $row = $this.closest("tr");'
                                        . '$.post("' . Url::to(['get-price-item', 'id' => '']) . '" + $(this).val(), function(data) {
                                                  $row.find(".harga-jual").val(data.price.harga);
                                           });']
                                    )
                                    ?>

Thanks again

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.