jQuery textbox required validation based on another text box having text

Posted by doug on Stack Overflow See other posts from Stack Overflow or by doug
Published on 2010-05-13T17:09:43Z Indexed on 2010/05/13 17:14 UTC
Read the original article Hit count: 200

Filed under:

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?

© Stack Overflow or respective owner

Related posts about jquery-validate