Skip to content

Instantly share code, notes, and snippets.

@wholypantalones
Created May 15, 2012 21:01
Show Gist options
  • Select an option

  • Save wholypantalones/2705110 to your computer and use it in GitHub Desktop.

Select an option

Save wholypantalones/2705110 to your computer and use it in GitHub Desktop.
Show/Hide password fields
<input type="password" id="OLD_PASSWORD" name="OLD_PASSWORD" value="" />
<input type="checkbox" value="option" id="showPass" name="showPass" />
$(function() {
$("#showPass").click(function() {
if($('#showPass').attr('checked')) { //can use .is(':checked') also
$("input[type=password]").each(function() { //iterate through all of type=password
$(this).clone().attr("type", "text").appendTo($(this).parent()).val($(this).val());
$(this).remove();
});
} else if($('#showPass').is(':not(:checked)')) {
$("input[type=text]").each(function() {
$(this).clone().attr("type", "password").appendTo($(this).parent()).val($(this).val());
$(this).remove();
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment