Page 1 of 1

show/hide plain text of password field when checkbox clicked

Posted: Mon Sep 27, 2010 12:09 pm
by samjose
good evening everybody
i just wanna ask if somebody could help me with problem.

when registering a new user i just wanna add a checkbox beside a password field so that in case the user forgot the content of the password he/she can view it easily by this feature.

when checkbox clicked = show plain text.
when checkbox no clicked = show password field character.

thanks.

Re: show/hide plain text of password field when checkbox cli

Posted: Mon Sep 27, 2010 2:20 pm
by DigitalMind
Hi! :)

Code: Select all

<html>
    <head>
        <script type="text/javascript">
        <!--
        function ShowHide() {
            if (document.getElementById('radio1').checked) {
                document.getElementById('secret').type = 'text';
            } else {
                document.getElementById('secret').type = 'password';
            }
        }

        //-->
        </script>
    </head>
    <body>
        <form id="form1">
            <input type="password" id="secret"><br>
            <label><input type="radio" id="radio1" name="radio1" value="on" onchange="ShowHide();">Show</label>
            <label><input type="radio" id="radio2" name="radio1" value="off" onchange="ShowHide();" checked>Hide</label>
        </form>
    </body>
</html>

Re: show/hide plain text of password field when checkbox cli

Posted: Wed Oct 06, 2010 8:57 am
by mkz
Changing the type of an input field with JavaScript does not work in all browsers (I think IE is the problem).

I don't have the link anymore but someone had solved it by deleting the input element and replacing it with a new one with the desired type.