I have been working on a project that requires me to toggle between showing and hiding the password in a password field.
The JS code I came up with is:
<script>
function text(item) {
if (document.getElementById('password').type = "password") {
document.getElementById('password').type = "text";
} else {
document.getElementById('password').type = "password";
}
}
</script>
<input type="checkbox" id="logon-show-password" name="showpassword" class="tickable" onclick="text(this)">
<input type="password" id="password" />
For some reason, it works just fine when toggling between password -> text, but fails to do the opposite.
What am I doing wrong?