Is there a way to make checkboxes act like radio buttons? I assume this could be done with jQuery?
<input type="checkbox" class="radio" value="1" name="fooby[1][]" />
<input type="checkbox" class="radio" value="1" name="fooby[1][]" />
<input type="checkbox" class="radio" value="1" name="fooby[1][]" />
<input type="checkbox" class="radio" value="1" name="fooby[2][]" />
<input type="checkbox" class="radio" value="1" name="fooby[2][]" />
<input type="checkbox" class="radio" value="1" name="fooby[2][]" />
If one box was checked the others in the group would uncheck.
$("input:checkbox").click(function(){
var group = "input:checkbox[name='"+$(this).attr("name")+"']";
$(group).attr("checked",false);
$(this).attr("checked",true);
});
This will do it, although i do agree this might be a bad idea.
Online example: http://jsfiddle.net/m5EuS/1/
UPDATE added group separation.
Updated for Jquery 1.9 - use .prop() instead of .attr()
$("input:checkbox").click(function(){
var group = "input:checkbox[name='"+$(this).prop("name")+"']";
$(group).prop("checked",false);
$(this).prop("checked",true);
});
Here is an example: http://jsfiddle.net/m5EuS/585/
If you apply class to the checkbox, you can easily achieve the radio button functionality using the following piece of code:
$(".make_radio").click(function(){
$(".make_radio").not(this).attr("checked",false);
});