Takaya213
5/2/2013 - 7:53 AM

A jQuery method to show and hide passwords in forms.

A jQuery method to show and hide passwords in forms.

$(document).ready(function(){
  $('.showpassword').each(function (index, input){
	    var $input = $(input);
		$("#passwordshow").click(function () {
			var change = $(this).is(":checked") ? "text" : "password";
			var text = $(this).is(":checked") ? "Hide Password" : "Show Password";
			var rep = $("<input type='" + change + "' />")
                .attr("id", $input.attr("id"))
                .attr("name", $input.attr("name"))
                .attr('class', $input.attr('class'))
                .val($input.val())
                .insertBefore($input);
            $input.remove();
            $input = rep;
            $('label[for="passwordshow"]').html(text);
        });
	});
});