I am trying to process a form using Ajax and have been having a problem with processing check boxes. I thought I could do an array inside an array which would add the checked boxes to the data object but that doesn't seem to be working. It doesn't show up as a part of the object in the console or anything like that. I tried a few variations and nothing was working. This is what it looks like currently:
var formData = {
'fname' : $('input[name=fname]').val(),
'lname' : $('input[name=lname]').val(),
'phone' : $('input[name=phone]').val(),
'email' : $('input[name=email]').val(),
'sqft' : $('select[name=sqft]').val(),
'checked': $('input[name=services[]]:checked').each(function(){
checked.push($(this).val());
});
};
I know I could use serialize() but honestly I am simply not familiar with processing data from that method. Since I need to process the data with PHP I wanted to stick with what I know.
This is the markup for the checkboxes:
<div class="checks span6">
<p>Check which services you are interested in:</p><br>
<input type="checkbox" name="services[]" value="janitorial"><p>Janitorial</p><br>
<input type="checkbox" name="services[]" value="window"><p>Window cleaning</p><br>
<input type="checkbox" name="services[]" value="carpet"><p>Carpet service</p><br>
<input type="checkbox" name="services[]" value="restroom"><p>Restroom sanitation</p><br>
<input type="checkbox" name="services[]" value="facility"><p>Facility Maintenance</p><br>
<input type="checkbox" name="services[]" value="floors"><p>Floor strippin & re-waxing</p><br>
<input type="checkbox" name="services[]" value="moving"><p>Move in or move out</p><br>
<input type="checkbox" name="services[]" value="other"><p>Other</p><br>
</div>
$_POST['services']should contain the selected checkboxes in a form of array, if you use ajax to transport it to PHP, the answer below if correct. +1