I have an array of checkboxes that gets built from a smarty template. When a particular checkbox is selected with a value of WTOPS, I want this action to select all the other checkboxes in the div. Here is my code below which is not working
Here is my jquery:
$("input[name=levelCheck]").change(function () {
if ($("input[name=levelCheck]:checked").val() == 'WTOPS') {
$("input[type='checkbox']").attr('checked', true);
}
});
Here is the HTML:
<div id="Women">
<label> <input type="checkbox" name="level_desc[]" id="levelCheck" value="WOPEN"> Open </label>
<label> <input type="checkbox" name="level_desc[]" id="levelCheck" value="WPREPOPT"> Prep Opt </label>
<label> <input type="checkbox" name="level_desc[]" id="levelCheck" value="WTOPS"> TOPS </label>
</div>
Below script should do the trick for the markup you have,
DEMO
As Michael pointed out, using quotes looks better,