1

I have a page with multiple checkboxes. I need to select all and submit via ajax.

function SelectedContactsMult(actMult) {    
    var data = { "delCont[]" : [] };
    $(".chkbx").each(function() {
        data["delCont[]"].push($(this).val());
    });     
    $.post("ajax.php?op="+actMult, data);
}

I get to my ajax page OK but I don't think I get any values... What am I missing here?

0

2 Answers 2

3
var arr=[];

$.each($("input[type='checkbox']"),function(){
    arr.push($(this).val());
});

    $.post("ajax.php?op="+actMult, {data:arr});
Sign up to request clarification or add additional context in comments.

Comments

1

Let's assume that you have actual checkbox inputs such as:

<input type="checkbox" name="delCont[0]" class="chkbox" /> Choice 1
<input type="checkbox" name="delCont[1]" class="chkbox" /> Choice 2
...

You can then serialize them as:

function SelectedContactsMult(actMult) {        
    $.post("ajax.php?op="+actMult, $('.chkbox').serialize() );
}

Note it's important that each of the checkboxes include the "id" of the choice, since unchecked checkboxes won't be posted back and you'll need to be able to distinguish which checkboxes are checked. The names could be related to the choice, not a generic "array" notation, but it's important to know which ones, not just that some number have been selected.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.