0

I have few checkbox like this,

<input type='checkbox' name='name[]' value='1' />
<input type='checkbox' name='name[]' value='2' />
<input type='checkbox' name='name[]' value='3' />
<input type='checkbox' name='name[]' value='4' />
<input type='checkbox' name='name[]' value='5' />

And my php processing code is below,

<?php
$check=$_POST['name'];

foreach($check as $arr){
//code for saving data in database
}

My problem is, I am trying to send the check box data via jquery/ajax. But I could not send those data to the php page as an array.

Please tell me I could I do that.

2 Answers 2

2

You can just serialize() or serializeArray() the checkboxes and send them to PHP :

$.ajax({
    url  : 'processing.php',
    data : $('[name="name[]"]').serialize()
}).done(function(result) {
    // ta da
});

Note that only checked boxes will be serialized, as there is generally no need to do anything for unchecked boxes.

0
0

View

        <input type='checkbox' name='name[]' class="checkBoxGroup" value='1' />
        <input type='checkbox' name='name[]' class="checkBoxGroup" value='2' />
        <input type='checkbox' name='name[]' class="checkBoxGroup" value='3' />
        <input type='checkbox' name='name[]' class="checkBoxGroup" value='4' />
        <input type='checkbox' name='name[]' class="checkBoxGroup" value='5' />

Script

        $ary=$(".checkBoxGroup").serializeArray();
        alert($ary[0]['value']);

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.