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

How to show enlarge image when mouse hover on image or link in Asp.Net(c#) using JavaScript

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

How to add custom filter lookup field based on OptionSet field selection in Dynamics CRM.

go to top image