making checkbox to be single select
making checkbox to be single select
HTML
<div>
<h3>Fruits</h3>
<label>
<input type="checkbox" class="radio" value="1" name="fooby[1][]">Kiwi</label>
<label>
<input type="checkbox" class="radio" value="1" name="fooby[1][]">Jackfruit</label>
<label>
<input type="checkbox" class="radio" value="1" name="fooby[1][]">Mango</label>
</div>
JavaScript
// the selector will match all input controls of type :checkbox
// and attach a click event handler
$("input:checkbox").on('click', function() {
// in the handler, 'this' refers to the box clicked on
var $box = $(this);
if ($box.is(":checked")) {
console.log("the box selected is ---> :"+$box.parent().text());
// the name of the box is retrieved using the .attr() method
// as it is assumed and expected to be immutable
var group = "input:checkbox[name='" + $box.attr("name") + "']";
// the checked state of the group/box on the other hand will change
// and the current value is retrieved using .prop() method
$(group).prop("checked", false);
$box.prop("checked", true);
} else {
console.log("something has been unchecked it is "+$box.parent().text());
$box.prop("checked", false);
}
var bolVal = false || true || false;
console.log(bolVal);
});