JQuery mask when typing text

0

I've been researching some Jquery masks to apply to a system, but I noticed that in some examples the mask is displayed when the input is clicked, and in other cases the mask is applied while typing.

How do I get the second case? I'm currently using the code below and got the first option.

    <head>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/jquery.maskedinput.js"></script>
</head>
<script type="text/javascript">
$(document).ready(function(){
    $("input.estoque").mask("999.99");
});
</script>
<body>
<label for="EST_MIN">
    <input type="text" class="estoque" name="EST_MIN" id="EST_MIN" MAXLENGTH="6"        value="" />
</label>
    
asked by anonymous 29.08.2014 / 20:20

2 answers

1

I always have issues with these masks, I simply change the way they are called to make them work. For example you can change the implementation of it and put in the event on focus below an example.

jQuery(function($){
   $(".estoque").live('focusin',function(){
       $(this).mask('999.99');
   });
});
  

The live method depends on the version of your jQuery if it does not work, change it to the on method as an example below.

jQuery(function($){
   $("input").on('focusin','.estoque',function(){
       $(this).mask('999.99');
   });
});
    
30.08.2014 / 15:59
0

You may be wanting the numbers to start typing from right to left, that is, formatting as you type.

You can use jquery.inputmask.js that has this possibility. You can see more about this jquery plugin (and its extensions) at link

Note the first Decimal field it has as an example. It must be what you want. Review its source code to see how to call and what files to download.

    
30.08.2014 / 15:20