Translate

Sunday, 22 September 2013

Change Password using Javascript

index.php:


<form name="form1"  method="post" onsubmit="return checkPasswordMatch();" >
<ul>
<li>
    <label for="usermail">Email</label>
    <input name="usermail" size="40"  required="" type="email" />
</li>

<li>
    <label for="password">Password</label>
  <input type="password"  id="txtNewPassword" size="40" required="required" autocomplete="off" name="password"></li>
                  
<li>
     <label for="password">Re-Password</label>
      <input type="password"  autocomplete="off" size="40" id="txtConfirmPassword" required="required"  name="password2">
</li>
                    
   <p class="registrationFormAlert" style="color:#F00; font-size:16px; margin:3px;" id="divCheckPasswordMatch">
</p>

<p align="center"><input type="submit"   value="Sign up"  name="go"></p>


</ul>
</form>

Script:


function checkPasswordMatch() {
    var password = $("#txtNewPassword").val();
    var confirmPassword = $("#txtConfirmPassword").val();

    if (password != confirmPassword)
    {
     $("#divCheckPasswordMatch").html("Passwords do not match!  Try Again ") 
     document.oo.password2.focus();
     return false;
    }
        else
        {
    $("#divCheckPasswordMatch").html("Passwords match. GOOD");
    
        }
}

No comments:

Post a Comment