New course! Every coder should learn Generative AI!
Try a free lesson+ 2
How to change the masking character of a password field?
Is it possible to change the masking character of a password input field in HTML from its default value . (bullet) to something else like * (asterisk), # (hash), x etc.? I guess it will involve JS but not sure how to go about it. Any suggestions/solutions would be much appreciated.
10 Answers
+ 1
Yes, check this out
https://sololearn.com/compiler-playground/WfV016XfnesO/?ref=app
+ 2
IAmSupreme great that's working! Thanks a lot 👍
+ 1
KnightBits I used your same code you gave above 👆
+ 1
KnightBits alright I'll try that, thanks again 👍
+ 1
Tharun Chandramohan you're welcome
0
Yes, you can change the masking character of a password input field using JavaScript. Here's a simple example using HTML and JavaScript:
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Masking Example</title>
</head>
<body>
<label for="password">Password:</label>
<input type="password" id="password" oninput="maskPassword(this.value)">
<script>
function maskPassword(value) {
// Choose your desired masking character (e.g., '*')
const maskingCharacter = '*';
// Replace each character in the input with the chosen masking character
const maskedValue = maskingCharacter.repeat(value.length);
// Set the masked value back to the input field
document.getElementById('password').value = maskedValue;
}
</script>
</body>
</html>
0
@KnightBits
I tried the same code you gave but it still comes in ... and not ***. Did it work for you?
0
Did i can see ur code?
0
Lol. Try this at another ide. I recommended u VSCode. There you can track errors and applied styles to elements through the chrome developer tool
0
Hggc