Toggle Password Visibility using JavaScript

Toggle Password Visibility using JavaScript

14-Sep-2024
| |
Image Carousel

Table of Contents

S.no Contents-topics
1 Introduction
2 Javascript code
3 Toggle Password Visibility using JavaScript

1:Introduction

Toggle Password Visibility is most commonly used in most sites to show you that you can crosscheck whether you have written the correct password. It is a very simple JavaScript code as you can see we created a function and in that function we have just called the document.getElementById in a variable and we will get what ever password is written in that input type.

2:Javasript code

Javascript code: Copy

<!DOCTYPE html>
<html>
<body>
<h1>Toggle Password Visibility using JavaScript</h1>
<p>Click the radio button to toggle between password visibility:</p>
 
Password: <input type="password" value="Developer Corner" id="myInput"><br><br>
<input type="checkbox" onclick="togglepassword()">Show Password
 
<script>
function togglepassword() {
  var x = document.getElementById("myInput");
  if (x.type === "password") {
    x.type = "text";
  } else {
    x.type = "password";
  }
}
</script>
 
</body>
</html>

Output

3:Toggle Password Visibility using JavaScript

Click the radio button to toggle between password visibility:

Password:

Show Password

Tags: Toggle, Password, JavaScript,JavaScript,
0 Comments (Please let us know your query)
Leave Comment
Leave Comment
Articles from other Categories
Load More

Newsletter