Skip to content

Instantly share code, notes, and snippets.

@AmrMekkawy
Last active February 23, 2018 03:35
Show Gist options
  • Select an option

  • Save AmrMekkawy/8b84a53fe1f295a9887247560fb2b0dd to your computer and use it in GitHub Desktop.

Select an option

Save AmrMekkawy/8b84a53fe1f295a9887247560fb2b0dd to your computer and use it in GitHub Desktop.
Toggle Password Visibility
/**
* 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