javascript - Mask is not working? -


enter image description here enter image description here

i have inputbox mask, inputs not allowed hardware keyboard, instead have touch-screen keyboard() function inserts characters in field.

but when keyboard() inserts inputs in input field fails generate mask effects.

how make mask work when keyboard() used?

<script type="text/javascript" src="http://digitalbush.com/wp-content/uploads/2014/10/jquery.maskedinput.js"></script> <script type="text/javascript">  function keyboard(input) {   if (input==='backspace') {     tvalue = '';   } else if(input ==='quote') {     tvalue = tvalue + "'";   } else if(input ==='space') {     tvalue = tvalue + " ";   } else {     tvalue = tvalue + input;   }       $('#' + tinput).val(tvalue);   console.log(">>> keyboard: ", input); }  $(document).ready(function(){   $("#rrn").mask('99.99.99-999.99');  //  $(document).bind('contextmenu', function()  { //    console.log('touch screen, has no right click.'); //    return false; //  }); //   //  $(document).mousedown( function() { //    return false;  //  });  }); </script>   <div>   <input type="text" name="rrn" id="rrn" style="position: absolute; left: 519px; top: 195px; width: 366px; height: 42px;border:none;" autocomplete="off"  onclick="inputselected(this, event);"/>       <img src="images/nl/keyboard.png"  border="0" usemap="#map_logo_new" id="spmain_new" />   <map name="map_logo_new">   <area shape="rect" coords="825,19,910,74" href="#" onclick="keyboard(0);">   <area shape="rect" coords="22,83,107,138" href="#" onclick="keyboard('a');">      </map>      </div> 

you programmatically setting value of input, not cause events trigger. in order force mask applied, need trigger event (after calling .val()).

try changing this:

  $('#' + tinput).val(tvalue).trigger('input'); 

jsfiddle


this jquery masked input plugin josh bush @ digitalbush.com.


at time latest version of libary v1.4. earlier version of library may have try 'click' event.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -