Your code...
$().ready(function () {
// validate UserSettings form on keyup and submit
$('#CheckBox').click(function () {
$("#TextBox").validate({
rules: {
NextLocation: {
required: true
}
}
});
});
});
... has the following issues...
1) $().ready() is not recommended as per jQuery docs. Use $(document).ready() instead.
2) You cannot attach .validate() to an input element. It only gets attached to the <form> element.
3) The .validate() method is only used for initializing the plugin, not for testing anything. Therefore, it typically does not belong inside of a click handler. You would fire .validate() only once as soon as the form is constructed, typically within the DOM ready handler.
4) If you want to make something required depending on the state of something else, you would use the depends method within the required rule.
My working demo below shows that the text field named NextLocation is only required when the checkbox named check is not checked:
$(document).ready(function () { // DOM ready handler
$('#myform').validate({ // attach to form to initialize plugin with options
rules: {
NextLocation: {
required: {
depends: function () {
return !$('input[name="check"]').is(':checked');
}
}
}
}
});
});
HTML:
<form id="myform">
Checkbox: <input type="checkbox" name="check" />
NextLocation: <input type="text" name="NextLocation" />
</form>
DEMO: http://jsfiddle.net/dymmw/