Jquery mask when typing text

Asked

Viewed 1,677 times

0

I have been researching some Jquery masks to apply on a system, but I noticed that in some examples the mask is displayed when you click on the input, and in other cases the mask is applied during typing.

How do I get the second case? I am 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>

2 answers

1

I always have trouble with these masks, I just change the way the call works. For example you can change its implementation and put in the event on Focus follows an example below.

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

The live method depends on your jQuery version if it doesn’t work change it to the on method as example below.

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

0

Maybe you want the numbers to start typing from right to left, that is, formatting while typing.

You can use jquery.inputmask.js which has this possibility. You can see more about this jquery plugin (and its extensions) in http://bseth99.github.io/projects/jquery-ui/5-jquery-masks.html

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.