jQuery textbox required validation based on another text box having text
- by doug
Pretty basic question, however, I am very new to jQuery and javascript in general.
I have a jQuery validation that is requiring a text box to have text in it, if a checkbox is checked.
<script type="text/javascript">
$(document).ready(function () {
$("form").validate(
{
rules:
{
Comments: {
required: "#IsAbnormal:checked"
}
},
messages:
{
Comments: {
required: "Comments are required"
}
},
onkeyup: false,
wrapper: "",
errorLabelContainer: "#ErrorMessageBox"
});
});
Pretty straight forward, if you check the IsAbnormal checkbox, it will throw a validation if there are no comments. What I am trying to do is require a textbox based on if another text box has any text in it, for instance require the old password if a user enters a new password into a textbox. Is there an easy way to get the required: "#NewPassword:NotBlank" to work?