javascript - Mask is not working? -
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');
this jquery masked input plugin josh bush @ digitalbush.com.
- http://digitalbush.com/projects/masked-input-plugin/
- https://github.com/digitalbush/jquery.maskedinput
at time latest version of libary v1.4. earlier version of library may have try 'click'
event.
Comments
Post a Comment