mardi 1 septembre 2015

Jquery show success image in the current row if checkbox is checked

I have this code:

<script>
$(document).ready(function() {
    $("#div_trattamenti").on('change', '.inpt_chkbox_trattamenti', function (e) {
        e.preventDefault();
        if($(this).is(":checked")){
        var id =  $(this).attr('rel');
        var value = $(this).val();
        alert(value);                                                                                                                           // prezzo
        }if($(this).is(":not(:checked)")){
            var id =  $(this).attr('rel');
            var value = 0;
            alert(value);                                                                                                                           // prezzo
        }

        data_chk = 'id=' + id + '&value=' + value;

        $.ajax({
            type: "POST",
            data: data_chk,
            cache: false,
            url: "php/aggiorna_chiuso.php",
            success: function(html){
                               var obj = $.parseJSON(html);
                                $.each(obj,function(index, element){
                                    var value2 = element.chiuso;                                // value chiuso
                                    }); // fine .each
                                if(value == 1){
                                    $('.chkmk_img_trattamenti', this).show();
                                }
                                if(value == 0){
                                    $('.chkmk_img_trattamenti', this).hide();
                                }
            },                                                                                  // fine success
            error: function(xhr, status, error) {
                console.log(status);
                console.log(error);
                console.dir(xhr);
                }                                                                       // fine error
            });                                                                         // fine ajax
    });
});
</script>

it works but I am not able to show the image only for the selected row (when user click checkbox).

I tried this but it doesn't work.. :

$('.chkmk_img_trattamenti', this).show();




Aucun commentaire:

Enregistrer un commentaire