I have tried to look on SO for a solution similar to mine and I couldn't find anything.
I have 4 checkboxes on my website
<label class="control-label" for="last_name"><strong>Filtering Options</strong> </label>
<div style='color: #777; font-size: 16px;'><td class='text-center'> <input type='checkbox' name="filters" id='city_checkbox' class='checkbox filters' $lstr_completed_city value="location_city"/> </td> City </div>
<div style='color: #777; font-size: 16px;'><td class='text-center'> <input type='checkbox' name="filters" id='county_checkbox' class='checkbox filters' $lstr_completed_county value="location_zip"/> </td> County </div>
<div style='color: #777; font-size: 16px;'><td class='text-center'> <input type='checkbox' name="filters" id='region_checkbox' class='checkbox filters' $lstr_completed_region value="location_region"/> </td> Region </div>
<div style='color: #777; font-size: 16px;'><td class='text-center'> <input type='checkbox' name="filters" id='country_checkbox' class='checkbox filters' $lstr_completed_country value="location_country"/> </td> Country</div>
What I want to do is whenever ANY of them is clicked, I want to cycle through all of them, seem which ones are checked, get their values and update the MySQL based on the selections. I'm pretty sure I will be fine with the PHP/MySQL part but I am struggling with the jQuery to get the values.
Lets take this as an example. Checkbox 1 and 3 are selected, 2 and 4 are not. I only want to post the values of checkbox 1 and 3. Then if checkbox 2 is added to the selection, I want to post values of checkbox 1, 2 and 3.
This is what I have tried so far. It reacts when I click on any checkbox but I'm just unsure as to how I go about getting specific values.
$('.filters').on('ifClicked', function(event)
{
var temp_id = event.target.id;
current_cb_element = temp_id;
var chckValue = $('#' + current_cb_element).parent('[class*="icheckbox"]').hasClass("checked");
if (chckValue)
chckValue = 0;
else
chckValue = 1;
$("input[name=filters]").each( function () {
alert( chckValue );
});