Advertisement
cdsatrian

toggle password input

Dec 21st, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2.     <head>
  3.     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  4.     <style type="text/css">
  5.         #password {
  6.             border: 1px solid #f00;
  7.         }
  8.     </style>
  9.     </head>
  10.     <body>
  11.         <input type="password" name="password" id="password" class="showpassword" />
  12.     </body>
  13. <script type="text/javascript">
  14. $(function(){
  15.     $(".showpassword").each(function(index,input) {
  16.         var $input = $(input);
  17.         $('<label class="showpasswordlabel"/>').append(
  18.             $("<input type='checkbox' class='showpasswordcheckbox' />").click(function() {
  19.                 var change = $(this).is(":checked") ? "text" : "password";
  20.                 var rep = $("<input type='" + change + "' />")
  21.                     .attr("id", $input.attr("id"))
  22.                     .attr("name", $input.attr("name"))
  23.                     .attr('class', $input.attr('class'))
  24.                     .val($input.val())
  25.                     .insertBefore($input);
  26.                 $input.remove();
  27.                 $input = rep;
  28.              })
  29.         ).append($("<span/>").text("Show password")).insertAfter($input);
  30.     });
  31. });
  32. </script>
  33. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement