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>
<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
Post a Comment