Jump to content

Javascript hide/show password field help


dsp77

Recommended Posts

i have figured how to change the input type from password to text but i could not make it back from password to text with the same button.

<input type="password" name="myElement" id="pass" value="some text" />
<input name="show password" type="button" onclick="document.getElementById('pass').type = 'text';" />

any advise please

 

Link to comment
https://forums.phpfreaks.com/topic/212666-javascript-hideshow-password-field-help/
Share on other sites

You mean to toggle the type? Try this:

 

function toggleType() {
    var obj = document.getElementById('pass');
    if (obj.type == 'text') {
        obj.type = 'password';
    } else {
        obj.type = 'text';
    }
}

 

Then call it with:

 

onclick="toggleType();"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.