Make a rule using the the max method and a function as a parameter. This will get evaluated when the field is validated, ie when element() is called on the field.
rules definition looks like this
rules: {
field1:
{
required: true,
max: function () { return $("#mycheckbox:checked").length ? 100 : 50; }
}
}
Also, revalidate the target field when rule changes or you may be left with an error message that no longer applies
$('#mycheckbox').on('change', function () {
$('#field1.error').each(function () {
$(this).valid();
});
});
note that this only revalidates the field if it is already validated, checking for the presence of the default errorClass 'error'.
with html like this
<input name="mycheckbox" id="mycheckbox" type="checkbox" />
<input name="field1" id="field1">
<input type="submit" />
Full JavaScript code is like this, find the fiddle here
$(function () {
$("form").validate({
rules: {
field1:
{
required: true,
max: function () {
return $("#mycheckbox:checked").length ? 100 : 50;
}
}
},
submitHandler: function () {
alert('form ok');
}
});
$('#mycheckbox').on('change', function () {
$('#field1.error').each(function () {
$(this).valid();
});
});
});