i have one problem controlling checkbox, i’m reading, and searching about the topic but i can’t find anything that works for me, first i have 3 checkboxes on a asp.net mvc form
<%= Html.CheckBox("cbCodigo") %> <label class="inline" for="Codigo">Codigo</label>
<%= Html.CheckBox("cbNombreCliente") %> <label class="inline" for="NombreCliente">Nombre del cliente</label>
<%= Html.CheckBox("cbCiudad") %> <label class="inline" for="Ciudad">Ciudad</label>
i want to control using jquery, that the user, just can check one of the checkbox, i try to use hide(); if the user check one checkbox the others just hide, but the control of the events is so hard, that isn’t the best way to do that i think.
thanks
Edit: answer to my own question
i know it´s just to rare hide the other options, i just want to “lock” the other options when i checked one of them, i solve it with this:
$('#cbCodigo').change(function() {
if ($(this).is(':checked')) {
$('#cbNombreCliente').prop("checked", false);
$('#cbCiudad').prop("checked", false);
}
});
$('#cbNombreCliente').change(function() {
if ($(this).is(':checked')) {
$('#cbCodigo').prop("checked", false);
$('#cbCiudad').prop("checked", false);
}
});
$('#cbCiudad').change(function() {
if ($(this).is(':checked')) {
$('#cbCodigo').prop("checked", false);
$('#cbNombreCliente').prop("checked", false);
}
});
Though I can’t really understand why do you need such a weird requirement.
Don’t you want letting the user revert his choice with other checkbox?