lundi 19 mars 2018

storing indeterminate checkbox state

I've got some js to toggle my check boxes between checked indeterminate and unchecked. when the check box is checked it stores in my database as 1 when it is unchecked stores as 0 however i cannot figure out how to store a value when the checkbox is on indeterminate state it just sets it to 0. I've tried an onclick function I've tried getElementById I've tried setAttribute however nothing seems to work. The column does not have a default value in my db any help would be greatly appreciated !

PHP

 $schDone =isset($_POST['schDone']);

JS

  <script>
$("#some-checkbox").prop("indeterminate", true); // prop is jQuery 1.6+
var $check = $("input[type=checkbox]"), el;
$check
.data('checked',0)
.click(function(e) {

    el = $(this);

    switch(el.data('checked')) {

        // unchecked, going checked
        case 0:
            el.data('checked',1);
            el.prop('checked',true);
        document.getElementById("schDone").value = "1";

            break;


        // going indeterminate
        case 1:
            el.data('checked',2);
            el.prop('indeterminate',true);
            el.prop('checked',false);            
            document.getElementById("schDone").value = "3";

            break;

        // indeterminate going unchecked
        default:  
            el.data('checked',0);
            el.prop('indeterminate',false);
            el.prop('checked',false);
           document.getElementById("schDone").value = "0";
    }

});
    </script>

HTML

<td width="100px"bgcolor="#A7D0FE"><strong>Sch Done</strong></td>
<td><input type='checkbox' name='schDone' <?php if($row['schDone']==1){echo 'checked="checked"';}  ?> value="1" </p></td>




Aucun commentaire:

Enregistrer un commentaire