i have a little problem, i’m searching, but i can’t found what i need, i have 3 checkboxes and one textbox in a form, i need to validate that the user only can edit the text box if they alredy check one checkbox, and only can check one i try of this ways:
$("#tbCodCliente").validate({
rules: {
checkbox: {
required: 'input[type="checkbox"]:checked',
minlength: 1
}
},
messages: {
checkbox: "Please check at least one."
}
tbCodCliente is the textbox of the form
or try
('#tbCodCliente').change(function() {
if( $("input:checked").length == 0 ) {
//
$("#request-form").validate({
rules: {
checkbox: {
required: 'input[type="checkbox"]:checked',
minlength: 1
}
},
messages: {
checkbox: "Please check at least one."
}
});
//
}
});
This is my checkboxes code
<%= 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 would disable the textbox by default and then enable it (and force only one checked checkbox at a time) in your change event handler.
jsFiddle