Created
October 6, 2011 06:25
-
-
Save tatsuosakurai/1266664 to your computer and use it in GitHub Desktop.
jquery-show-password-toggle
This file contains 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
// 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