How do I code a switch to hide/show password?

Hi there,

I’m looking to use a switch/toggle on my wixsite to show/hide the users login/sign-up password on custom. I’ve been able to make it work using two separate buttons, however, would prefer to use a toggle.

Switch ID = #switch1
Password textbox input ID = #loginPassword

I’m aware that I may have to use onClick
export function switch1_click(event) {

and I have the following codes:
$w( “#loginPassword” ).inputType = “text”
$w( “#loginPassword” ).inputType = “password”

Thanks in advance!

1 Like

Hello.

You can do this using onChange to check for the checked status of the switch instead of the onClick event:

export function switch1_change(event) {
 if ($w("#switch1").checked) {
        $w("#loginPassword").inputType = "password";
    } else{
        $w("#loginPassword").inputType = "text";
    }

}

Good luck!

Superstar!

When I tried to set a textbox as password field, I would got the following error.

The input box for password is txtPassword.

$w . onReady ( function () {

 $w ( "#txtPassword" ). inputType  =  "password" ; 

});

Property ‘inputType’ does not exist on type ‘“#txtPassword”’.

When I log into Wix.com to access my site for editting, there is an icon to show/hide my password. Can Wix please send me the step-by-step instructions on how to add that function to my website for Users who need to sign-up and/or log-in to access the password protected Members Only pages . The Users want if not must have the icon to give them the option see their password like I can when I access Wix for editing. Thanks.

1 Like