Matt23

Show Password Inputs

May 10th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.addEventListener("keydown", function(event) {
  2.     if (event.keyCode === 192) changeStateOfInputs();
  3. });
  4.  
  5. var inputs = [];
  6. var types = ['text', 'password'];
  7. var theSwitch = false;
  8.  
  9. function fetchInputs() {
  10.     if (inputs.length !== 0) return;
  11.  
  12.     var allInputs = document.getElementsByTagName('input');
  13.     for (var i = 0; i < allInputs.length; i++)
  14.         if (allInputs[i].type == 'password') inputs.push(allInputs[i]);
  15. }
  16.  
  17. function changeStateOfInputs() {
  18.     fetchInputs();
  19.     for (var i = 0; i < inputs.length; i++) {
  20.         inputs[i].type = types[+theSwitch];
  21.     }
  22.     theSwitch = !theSwitch;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment