Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     Auto Spacer for input boxes
  3.     Written by: Alex Kovacs
  4. */
  5.  
  6. // Input box
  7. console.log("Loaded!");
  8. let monogram_input = document.querySelector('input.pplr_monogram');
  9.  
  10. // Add event listener
  11. monogram_input.addEventListener('input', function(e) {
  12.     console.log("Input");
  13.  
  14.     // Get string and split it.
  15.     let string = e.target.value.split(" ").join("");
  16.  
  17.     // If the string exists
  18.     if (string.length > 0) {
  19.         console.log("Input exists");
  20.         // Set whitespace to every other character and then join it
  21.         string = string.match(new RegExp('.{1,1}', 'g')).join(" ");
  22.     }
  23.  
  24.     // Set the value of the targer
  25.     e.target.value = string;
  26. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement