Skip to content

Instantly share code, notes, and snippets.

@tatsuosakurai
Created October 6, 2011 06:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tatsuosakurai/1266664 to your computer and use it in GitHub Desktop.
Save tatsuosakurai/1266664 to your computer and use it in GitHub Desktop.
jquery-show-password-toggle
// Sample
// http://aaronsaray.com/blog/2010/10/19/jquery-show-password-toggle/
// HTML
// <input type="password" name="password" id="password" class="showpassword" />
// <input type="password" name="password_confirmation" id="password_confirmation" class="showpassword" />
// <input type="checkbox" value="1" name="show_password" id="show_password">
// js
$(function(){
$(".showpassword").each(function(index,input) {
var $input = $(input);
$("#show_password").click(function() {
var change = $(this).is(":checked") ? "text" : "password";
var rep = $("<input type='" + change + "' />")
.attr("id", $input.attr("id"))
.attr("name", $input.attr("name"))
.attr('class', $input.attr('class'))
.attr('size', $input.attr('size'))
.val($input.val())
.insertBefore($input);
$input.remove();
$input = rep;
})
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment