1

I working on a sign up page which consists of several fields, all i wanna know how can i remove/hide the text from Password Confirmation textbox. when password and retype password does not match.

Here is my Code

$('#txtConfirmPassword').blur(function() {
  if ($('#txtConfirmPassword').val() != $('#txtPassword').val()) {
    $('#spPasswordConfirmation').html('Password and Retype Password does not match.');
  } else {
    $('#spPasswordConfirmation').html('')
  }
});

2 Answers 2

5

Use

$('#spPasswordConfirmation').val('');

instead of

$('#spPasswordConfirmation').html('');
Sign up to request clarification or add additional context in comments.

1 Comment

Thank You LulzAsh what i wanted to remove the text from the password confirmation text box, not the error message but i use the same technique(.val(' ')) for the confirmation text and it works thank you.
1

You can use .html('') if you want, but you have to clear the box itself #txtConfirmPassword

See jQuery .html(htmlString)

$('#txtConfirmPassword').blur(function() {

  let txtConfirmPassword = $('#txtConfirmPassword');
  let spPasswordConfirmation = $('#spPasswordConfirmation');

  if (txtConfirmPassword.val() !== $('#txtPassword').val()) {
    txtConfirmPassword.val('');
    spPasswordConfirmation.html('Password and Retype Password does not match.');
  } else {
    spPasswordConfirmation.html('');
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form>
  <input type="text" value="" id="txtPassword">
  <br>
  <input type="text" value="" id="txtConfirmPassword">
  <br>
  <span id="spPasswordConfirmation"></span>
</form>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.