mardi 8 août 2017

How to check if checkbox is unchecked

I have data which i get from datasbase and table with checkboxes:

    <tbody>
        <tr class="full_qst">
            <td><?php echo $driver; ?></td>
            <td><?php echo $subdriver; ?></td>
            <td><?php echo $skill; ?></td>
            <td> <img alt="" src="imagesAssessment/check.png" class="check">
                <div class="mrk">
                    <label class="choice" for="q1_a" ><input class="q" name="q1_a[]" type="checkbox" value="<?php echo $low ?>"/>1</label>
                    <label class="choice" for="q1_a" ><input class="q" name="q1_a[]" type="checkbox" value="<?php echo $middle ?>"/>2</label>
                    <label class="choice" for="q1_a" ><input class="q" name="q1_a[]" type="checkbox" value="<?php echo $good ?>"/>3</label>
                    <label class="choice" for="q1_a" ><input class="q" name="q1_a[]" type="checkbox" value="<?php echo $vrgood ?>"/>4</label>
                </div>   
                <input id="q" name="q[]" type="hidden" value="<?php echo $id; ?>" /> 
                <input name="dep[]" type="hidden" value="<?php echo $dep; ?>" />    
            </td>
        </tr>
    </tbody>

I want to check if checkbox for current row is checked if yes then make image visible, if not then make it hidden again:

$('input.q').on('change', function() {
   $(this).parents('.full_qst').find(".q[name='"+$(this).attr("name")+"']").not(this).prop('checked',false);
    if($(this).parents('.full_qst').find(".q[name='"+$(this).attr("name")+"']").length === 0)
    { $(this).parents('.full_qst').find('.check').css('visibility', 'hidden'); }
    else { $(this).parents('.full_qst').find('.check').css('visibility', 'visible'); }
});

But it doesnt work, how can I solve this problem?




Aucun commentaire:

Enregistrer un commentaire