Last active
February 23, 2018 03:35
-
-
Save AmrMekkawy/8b84a53fe1f295a9887247560fb2b0dd to your computer and use it in GitHub Desktop.
Toggle Password Visibility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * If the password input in your form has the name "password", then | |
| * you only need to pass the form object to the function. | |
| * But if your password input has a name other than "password", then you need to add | |
| * a class for it and pass that class name to the function with the form object. | |
| */ | |
| function togglePasswordVisibility($form, passwordInputClass) { | |
| var x; | |
| // If the user gave the password input a class name and passed it to the function | |
| if (typeof passwordInputClass != "undefined") { | |
| x = $form.find("." + passwordInputClass); | |
| // If he only passed the form object | |
| } else { | |
| x = $form.find("input[name=password]"); | |
| } | |
| for (i = 0; i< x.length; i++) { | |
| if (x[i].type === "password") { | |
| x[i].type = "text"; | |
| } else { | |
| x[i].type = "password"; | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment