开发者

java script is not working

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

function validate_form(thisform)
{  
with (thisform)
  {  
    if (val开发者_JS百科idate_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???


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.


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.


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜