jQuery - Unchecking checkboxes that act like radio buttons
- by Cecil
Hey All,
I have the following jQuery code to make my checkboxes act like radio buttons, so that only 1 of the 3 can be checked at a time.
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#testing input:checkbox").change(function(){
var checkname = $(this).attr("name");
$("input:checkbox[name='" + checkname + "']").removeAttr("checked");
this.checked = true;
});
});
</script>
The checkboxes are layed out like the following:
<input type="checkbox" id="testing" name="testing" value="B">
<input type="checkbox" id="testing" name="testing" value="I">
<input type="checkbox" id="testing" name="testing" value="A">
This works exactly how i want it to work, not a problem, except once i click one of the 3, i cant unclick it so that none of them are checked, this is what i want to happen, so along with being only able to click one at a time, im able to uncheck them completely.
Any help would be grand :)