Hide/ Show Password on button click by using JavaScript and Jquery

First of all add the below code inside your <head> tag ::


 <script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.js"></script>
 
<script type="text/javascript">
    $(function () {
        $('#showpwd').hide();

        $('#btnpwd').click(function () {
            var txt = $('#btnpwd').val()
            var pwd = $('#hidepwd').val();
            if (pwd.length > 0) {
                if (txt == 'Show Password') {
                    $(this).val('Hide Password');
                    $('#showpwd').val($('#hidepwd').val());
                    $('#showpwd').show();
                    $('#hidepwd').hide();
                    return false;
                }
                else if (txt == 'Hide Password') {
                    $(this).val('Show Password');
                    $('#showpwd').hide();
                    $('#hidepwd').show();
                    return false;
                }
            }
            else {
                alert('Plese Enter Password');
                return false;
            }
        });

    })
</script>



Then add code inside your <body> tag and check ::

 <div>
    Enter Password :
        <asp:TextBox ID="hidepwd" runat="server" TextMode="Password"></asp:TextBox>
        <asp:TextBox ID="showpwd" runat="server"></asp:TextBox>
        <asp:Button ID="btnpwd" runat="server" Text="Show Password" />
    </div>

Comments

  1. why this much of codes? Im not clear..because i found this article which does the same in few lines, and it works too..

    ReplyDelete

Post a comment

Popular posts from this blog

StateCode and StatusCode Values for mostly used entities in Microsoft Dynamics CRM 2013

How to import CSV files into DataTable in C#

Search data in Gridview on Textbox Key press event using JQuery in Asp.Net- C#

go to top image