show/hide plain text of password field when checkbox clicked

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
samjose
Forum Newbie
Posts: 1
Joined: Mon Sep 27, 2010 11:54 am

show/hide plain text of password field when checkbox clicked

Post 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.
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

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

Post 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>
mkz
Forum Newbie
Posts: 11
Joined: Tue Oct 05, 2010 10:37 am

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

Post 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.
Post Reply