0

I have two textbox in Asp.Net: first for password and second is for a matching password.

How can I validate whether user entered different value in both textboxes through JavaScript at client side?

2 Answers 2

3

Have you considered the CompareValidator control for this?

It's what the CompareValidator was designed for.

edit - added

If you just want the javascript and want to do it completely in javascript, here's an example:

http://www.willmaster.com/library/manage-forms/ensuring-two-form-fields-have-identical-information.php

However, the CompareValidator takes care of generating the javascript for you (as long as client side validation is turned on), so in my opinion (and it IS just an opinion) you're making it harder on yourself by writing the javascript yourself.

Sign up to request clarification or add additional context in comments.

2 Comments

bingo! Could also consider using the ChangePassword control
want javascript for validate them
2

The simplest js for this would be

if(document.getElementById('password1').value != document.getElementById('password2').value){
    // they do not match
}

But if you are using .NET, you might want to take the advice to use a CompareValidator.

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.