Hide Show Password in Bootstrap

 Hide Show Password

 

coding-zon-Hide-show-thumb

This tutorial teaches you how to create a password preview button in bootstrap login form. When the user clicks the preview button, the jQuery snippet captures the click event and changes the password type to text. In case if it is in text mode, it changes its type to password.

Copy the code, save the file with index.html and preview it in Browser. Then you will see the output as shown in below image. Now click the preview button and check how it is working. If any question pleases comment below.

 

index.html

<!DOCTYPE html>
<html lang="en">
<head>
<title>Toggle password Example</title>
 
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> 
 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css'>

<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.3/dist/jquery.slim.min.js"></script>  


<script>
	
$(document).ready(function() {
    $("#toggle_password a").on('click', function(event) {
	    event.preventDefault();
		if($('#toggle_password input').attr("type") == "text"){
		    $('#toggle_password input').attr('type', 'password');
		    $('#toggle_password i').addClass( "fa-eye-slash" );
		    $('#toggle_password i').removeClass( "fa-eye" );
		}else if($('#toggle_password input').attr("type") == "password"){
		    $('#toggle_password input').attr('type', 'text');
		    $('#toggle_password i').removeClass( "fa-eye-slash" );
		    $('#toggle_password i').addClass( "fa-eye" );
		}
	});
});
</script>
	
<style>
.login-form {
width: 340px;
margin: 50px auto;
font-size: 15px;
}
.login-form form {
margin-bottom: 10px;
background: #f7f7f7;
padding: 30px;
box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);

}
.login-form h2 {
margin: 0 0 15px;
}
.form-control, .btn {
border-radius: 2px;
min-height: 38px;

}
.btn {        
font-size: 15px;
font-weight: bold;
}
</style>
	
</head>
<body>
		
<div class="login-form">

<h2  class="text-center">Toggle Password</h2> 
<form>
	<h2 class="text-center">Log in</h2>   
 
	<div class="form-group"> 
	<div class="input-group" id="username">
	<input class="form-control" type="text" placeholder="Username">
		
	<div class="input-group-addon">
		<a href=""><i class="fa fa-user" aria-hidden="true"></i></a>
	</div>
	</div> 
	</div>
	<div class="form-group"> 
	<div class="input-group" id="toggle_password">
		<input class="form-control" type="password" placeholder="Password">
			
	<div class="input-group-addon">
		<a href=""><i class="fa fa-eye-slash" aria-hidden="true"></i></a>
	</div>
	</div> 
	</div>

	<div class="form-group">
		<button type="submit" class="btn btn-primary btn-block">Log in</button>
	</div>

</form>
</div>

</body>
</html>
 
 
Output:
 
coding-zon-Toggle-Password


 

Comments

Popular posts from this blog

Using javascript pass form variables to iframe src

Creating a new PDF by Merging PDF documents using TCPDF

Import excel file into mysql in PHP