lundi 4 avril 2016

How to submit all checkbox fields in the form?

I have my table with the list of checkboxes. If checkbox is checked value is set to 0, if it's unchecked then value is -1. My current code only submit check boxes if they are checked. I want to submit all check boxes in my form every time I hit save button. Is there any way I can do that? Here is my code:

HTML:

<input type="checkbox" name="user" value="~(user_ID)" class="chkBlock" />

JQuery:

//This code switch value based on if check box is checked or not
$j('.chkBlock').click(function(){
     $j(this).val(this.checked ? 0:-1);
});

and this code set check box status based on the values from DB:

$j( document ).ready(function() {
    $j('input.chkBlock[value="0"]').prop("checked", true);
    $j('input.chkBlock[value="-1"]').prop("checked", false);
    $j('input.chkBlock[value=""]').prop("checked", false);
});

My current code only submit value if it's checked.




Aucun commentaire:

Enregistrer un commentaire