1

I am not able to set custom attributes value with ajax success response in current selected select box.

I want to set ajax success response value in current selected selectbox.

Here is my code ..

HTML

<tr>
    <td>
        <select class="promo_code_box selected" id="promo_code_box">
            <option product_price="27.90" value="5"> 5% OFF</option>
            <option product_price="27.90" value="10"> 10% OFF </option>
            <option product_price="27.90" value="15"> 15% OFF </option>
            <option product_price="27.90" value="20"> 20% OFF </option>
            <option product_price="27.90" value="25"> 25% OFF </option>
            <option product_price="27.90" value="30"> 30% OFF </option>
        </select>

        <p class="update_promo_price" id="update_promo_price"></p>
    </td>
</tr>

<tr>
    <td> Same HTML here...</td>
</tr>   

<tr>
    <td> Same HTML here... </td>
</tr>   

JQuery Ajax Call

$(document).ready(function(){
    $('body').on('change','.promo_code_box',function(){ 
        $.ajax({
            type: "POST",
            url: 'get_promo_price_level.php',
            data: {'promo_code':$(this).val(),'origional_price':$('#product_origional_price').val(),},
            success: function(response)
            {
                var jsonData = JSON.parse(response);
                promoDiscount = jsonData.data;                          
                $(this).parent().attr("update",jsonData.data);  // Not work                     
                $(this).next().html(jsonData.data);     // Not work jasan data not added in update_promo_price                  
           }
       });
    }); 
});

In HTML there are tr td structure , Mean to say same select box html in each table row. So I want once change select box from particular table's row then ajax success value will be store into current select box's next element update_promo_price. I have tried everything is working fine but ajax success response value will not add into current select box next element.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • Hi, this is because `$(this)` is not been identify by your ajax . So , store it in some variable outside ajax i.e : `var selector = $(this)` then use inside i.e : `selector.parent()..` same for other . – Swati Feb 15 '21 at 12:41
  • @Swati, Thank's a lot . It's working now. I forgot to do this. Thank you once again for your time. :) – samir sheikh Feb 15 '21 at 12:50
  • You can also use `$.ajax` option `context:this,` – charlietfl Feb 15 '21 at 13:02

0 Answers0