Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Friday, 20 March 2015


While Creating sign up form it is needed to confirm password. This can be done by two methods:
1.      Server Side Code
2.      Javascript


In this article I will use Javascript code to compare passwords.

Source Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
        function compare() {
            var pass = document.getElementById("txtpassword");
            var confirmpass = document.getElementById("txtconfirmpassword");
            var Password = document.getElementById('<%=txtpassword.ClientID %>').value;
            var valid = pass.value == confirmpass.value;
            if (Password == "") {
                alert("Please Enter Password");
                return false;
            }
            if (!valid) {
                alert("Password do not match");
                return false;
            }

            else {

                return true;
            }
        }
</script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
    <center>
     <fieldset style="width:300px">
    <legend><strong>Compare Password Using Javascript</strong></legend>
    <table ><tr><td>
  
    </td></tr><tr><td>      
    <table>
    <tr>
    <td>Password:</td><td>
        <asp:TextBox ID="txtpassword" runat="server" placeholder="Enter Password" TextMode="Password"></asp:TextBox></td>
    </tr>
    <tr><td>Confirm Password:</td><td>
        <asp:TextBox ID="txtconfirmpassword" runat="server" placeholder="ReEnter Password" TextMode="Password"></asp:TextBox></td></tr>
        <tr><td>&nbsp;</td><td>
            <asp:Button ID="btncheck" runat="server" Text="Confirm"
                OnClientClick="return compare();" /></td></tr>
    </table>
    </td></tr></table>
    </fieldset></center>
    </div>
    </form>
</body>

</html>
Categories: , ,

0 comments:

Post a Comment