Verify password field

I want use javascript to for verify password field. The value in verify password field is supposed to be the same as in password field.
LVL 1
netazimAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

StingRaYCommented:
The password is not usually verified at the client browser. For security purpose, it is always sent to and verified at server.
Lee SavidgeCommented:
Passwords are verified on the server but if you have 2 boxes for the password and the only check you're doing is to ensure they're the same, this can be done in the browser.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Lee SavidgeCommented:
If you're checking a password typed in with one stored on the server you wouldn't use Javascript for this. You post it back to the server.
COBOLdinosaurCommented:
<script type="text/javascript">
function verify(x)
{
   if (document.getElementById(x).value != document.getElementById('pword').value)
   {
      alert ('verified password and password must match');
      return false;
   }
   return true;
}
</script>

Open in new window


and in the form:
Password: <input type="password" id="pword" />
verify password: <input type="password" onblur="verify(this.id)">

Open in new window




But as already stated you should be doing password validation on the server.



Cd&
netazimAuthor Commented:
TQ very much for your answer,

another question, if users do not fill one of the text fields, how do i check the empty field?
COBOLdinosaurCommented:
If one is blank then the if statement comparing them.  However ther is a good point ther that they could both be empty.  For good browsers you could use and additional attribute on the input: required="required" , however; as usual IE is defective and does not support it so we can modify the script to test this way:

<script type="text/javascript">
function verify(x)
{
   if (document.getElementById(x)=="" || document.getElementById(x).value != document.getElementById('pword').value)
   {
      alert ('verified password and password must be entered and must match');
      return false;
   }
   return true;
}

Open in new window



Cd&
</script>
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.