I have 5 checkboxes and only one is allowed. Lets say user clicks on check box one, but if he clicks on checkbox two, checkbox one has to be unchecked. How can I achieve this?
HTML
<div class="form-group form-group-custom" id="checkboxes">
<?php
foreach ( $education_levels_array as $key => $employee ) {
echo '
<div class="checkbox checkbox-inline">
<input class="educationCheckboxes" type="checkbox" name="userEducationDegree[]" id=0' . $employee['education_id'] . ' value="' . $employee['education_id'] . '" />
<label for=0' . $employee['education_id'] . '>' . $employee['education'] . '</label>
</div>';
}
?>
</div>
I tried to store it in a variable, but right now it won't let me select any options.
var lastChecked;
$(".educationCheckboxes").on("change", function () {
console.log(lastChecked);
if ($(this).prop("checked", true)) {
lastChecked = $(this);
}
lastChecked.prop("checked",false);
});