Jquery mask working only for one field

Asked

Viewed 2,137 times

2

Dear, in my code I must insert two mask, however, only of INSC_EST It’s working, the other one isn’t. Follows the code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<script type="text/javascript" src="../../js/jquery-1.7.min.js" ></script>
<script type="text/javascript" src="../../js/jquery-1.10.2.js"></script>
<script type="text/javascript" src="../../js/jquery-ui.js"></script>
<script type="text/javascript" src="../../js/jquery.maskedinput.js"></script>

    $(function() {$( "#datepicker" ).datepicker();});  
    $(function() {$( "#tabs" ).tabs();});
    $(document).ready(function(){
       $("input.INSC_EST").mask("999.999.999-9999");
       $("input.CGC").mask("99.999.999/9999-99");
    });

   <fieldset id="Fiscal" class="Fiscal">
     <legend><b>Fiscal:</b></legend>
       <label for="Natureza">
            Natureza:   
         <select name="NATUREZA">
           <option value="1">Pessoa Fisica</option>
           <option value="2" selected>Pessoa Juridica</option>
           <option value="3">Trading</option>
         </select>
       </label>
       <label for="CGC">
         CGC:<input type="text" class="CGC" name="CGC" id="CGC" value="" />
       </label>
       <label for="INSC_MUNIC">
         Insc. Municipal:<input class="class5" type="text" name="INSC_MUNIC" MAXLENGTH="11" value=""/>
       </label>
         <label for="INSC_EST">
         Insc. Estadual:    <input class="INSC_EST" type="text" name="INSC_EST" value=""/>
       </label>
         <label for="ST">
           ST: <select>
           <option value="1" selected>SIM</option>
           <option value="2">NAO</option>
           </select>
         </label>

  </fieldset>
</div>

  • I removed my answer, I think I missed the Plugin you are using...

1 answer

1


Your code works, the proof is here:

http://jsfiddle.net/ryw18wax/1/

What I noticed was that the masks are only applied when you enter all the numbers, which is probably not what you want.

Note that I made a small change here:

$("input.INSC_EST").mask("999.999.999-9999");
$("input.CGC").mask("99.999.999/9999-99");

Add the parameter re-verse for the component to format the field as you enter the values, this way:

$("input.INSC_EST").mask("999.999.999-9999", {reverse: true});
$("input.CGC").mask("99.999.999/9999-99", {reverse: true});

EDIT

This component is very well documented, follows a show case with several examples:

http://igorescobar.github.io/jQuery-Mask-Plugin/

  • Thanks for the answer, that’s exactly what I want. I saw that it is working, but unfortunately for me it is not working, I am still with the same case and , even inserting the Verse, this also does not work, because when clicking on the field the Mask is already shown.

  • @Thiago Does anything appear on the console? Why do you import two versions of jQuery?

  • Thank you so much for the answer, everything is working perfectly. The main error was in the jQuery-Mask-Plugin.js script. I downloaded it again and Mask worked even better thanks to Verse:true.

Browser other questions tagged

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