-1

i am comparing password and confirm password through java script.my code-

function validate_form(thisform)
{  
with (thisform)
  {  
    if (validate_required(password,"<b>Error: </b>Password must be filled out!")==false)  
  {password.focus();return false;}

  else if (validate_required(cnfpassword,"<b>Error: </b>Confirm Password must be filled out!")==false)
  {cnfpassword.focus();return false;}

  else if (document.getElementById('password').value != document.getElementById('cnfpassword').value)
  {password.focus();Sexy.error("<b>Error: </b>Passwords entered are not same!"); 
  password.value="";cnfpassword.value="";return false;}
  }

validate_required() function is working fine, it is showing alert msg but password compare is not working. But the same code is working fine in some other page.I have written some php code to avoid page caching-

<?php
session_start();
session_cache_limiter('nocache');
header('Pragma: no-cache');
?>

what's the problem???

5
  • It might help if you show us the html for the form the password inputs are on. Both for the working page and the non-working page. Commented May 18, 2010 at 19:08
  • Why do you have if clauses that are doing a comparison to false? It is already a boolean value, you can just not it to make the false return produce a true if clause. Commented May 18, 2010 at 19:09
  • javascript - as in, "my snippet of javascript is not working". Not "my java script is not working". That implies you're programming a script, with java (which is a bit odd). Sorry - pet peeve. Commented May 18, 2010 at 19:12
  • @unholy ....how please can u write that line. Commented May 18, 2010 at 19:19
  • The ! symbol is used to not the boolean result of your function and turn false to true. !validate_required(password,"<b>Error: </b>Password must be filled out!") Commented May 18, 2010 at 20:08

3 Answers 3

1

Strange code !

What does the

with (thisform)

do ? Does it allow to have password and cnfpassword in the current scope ?

If so, why don't you do :

else if (password.value != cnfpassword.value)

?

Apart from this, I suggest you to validate the form ALSO in PHP.

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

2 Comments

with is generally agreed to be a JavaScript mistake that should never be used. Unfortunately, the bloody awful example code on w3schools uses it, which is why we keep seeing this ugly and completely pointless validate_required function popping up again and again. Die, w3schools, die.
1

It probably has to do with the values themselves; do you have a javascript debugger to help you step through and see where the error is happening? If you're using Firefox, I recommend the addon Firebug.

Comments

0

make sure the form input id's are correct (password and cnfpassword). also if they are, you could try changing

if (document.getElementById('password').value != document.getElementById('cnfpassword').value)

to

if (password.value != cnfpassword.value)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.