Logic Error on Javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MATTXtwo
    New Member
    • Sep 2006
    • 83

    Logic Error on Javascript

    Code:
    <script language="javascript">
    <!--
    function ValidatePwd()
    { 
    valid = true;
    var NewP=document.getElementById("NPwd").value;
    var OldP=document.getElementById("OPwd").value;
    if (NewP.value == OldP.value)
    {
    alert("Change into new password,please!");
    document.getElementById("NPwd").value="";
    valid = false;
    }
    return valid;
    }
    //-->
    </script>
    <body>
    
    <table border=0 cellspacing=0 cellpadding=0 width=100% height=100%>
    <tr align=center valign=top>
     <td>
    	<form method=post action=/Intranet/hr/Change_Password_db.asp  id=form1 name=form1 onSubmit="return ValidatePwd();">
    	 <BR><BR><BR>
    ...
    ....
    .....
    <td> <input type="password" maxlength="20" id="NPwd">&nbsp;&nbsp; <input type="submit" value="Submit" id="submit1" name="submit1" style="WIDTH: 80px; HEIGHT: 24px"></td>
    Help, the javascript always get alert wether it's true or not
  • Rsmastermind
    New Member
    • Sep 2008
    • 93

    #2
    Friend I really donot undeerstand why you have used this<-- no need second thing "var OldP=document.g etElementById(" OPwd").value; " from where you are fetching the id OPwd as this is nowhere in your code.Please make everything clear and transparent.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      You should be comparing NewP and OldP, not NewP.value and OldP.value because NewP and OldP are already set to the value!

      Comment

      • MATTXtwo
        New Member
        • Sep 2006
        • 83

        #4
        Hi Hi... got mistake coz long time no longer coding on asp
        I have make the correction on OldP and NewP with the thing OldP.value and NewP.value
        thanks guys anyway

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          So that means it's working now?

          Comment

          Working...