Mask input text output from a form - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

Mask input text output from a form

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <script>
function displayNumber(){// w  ww  .j  av  a 2  s .c om
   var card = document.getElementById('credit').value;
   var str = "";
   for(var i=1; i <= card.length-4; i++) {
      str += "*";
   }
   ecard = str + card.substr(card.length-4);
   document.getElementById('credit').value = ecard;
}

      </script> 
      <form id="myform"> 
         <input type="text" id="credit" onkeyup="displayNumber()"> 
      </form>  
   </body>
</html>

Related Tutorials