dimanche 29 janvier 2017

How to send multiple checkbox group values through ajax?

I am having three group of check boxes as follows:

echo '<input type="checkbox" name="metal[]" value="'.$value.'" id="'.$value.'" onclick="return submitForm()" ><label for="'.$value.'"></label>';
echo '<input type="checkbox" name="shape[]" value="'.$value.'" id="'.$value.'" onclick="return submitForm()"><label for="'.$value.'" ></label>';
echo '<input type="checkbox" name="type[]" value="'.$value.'" id="'.$value.'" onclick="return submitForm()"><label for="'.$value.'" ></label>';

All coming from database. I want to send these values through ajax. My current code is:

function submitForm() {
var form = document.myform;

var dataString = $(form).serialize();
$.ajax({
type:'POST',
url:'carousel.php',
data: dataString,
success: function(data){
    $('#myResponse').html(data);


}
});
return false;
}</script>

This function is sending only single value to carousel.php. I further want to process data and show result according to the checked values. Also on clicking another checkbox, previous checkbox values is lost. I found above code on google and very new to ajax. Please help.




Aucun commentaire:

Enregistrer un commentaire