I am not able to run the currency mask through Jquery

0

I'm trying to set up my inputs with a monetary mask. I called the script as follows:

<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="js/dist/jquery.mask.min.js">
    $(document).ready(function(){
    $('.money2').mask("#.##0,00", {reverse: true});
</script>

I created the following input:

<h4 id="cr1">Até 30 dias<input type="text" placeholder="R$ 0,00" id="cr11" name="ncr11" class="money2"/></h4>

I've also tried to replace the $ ('. money2') with $ ('# cr11') in the attempt to call the id.

In both cases (class or id) did not work, as you can see from the image below. You should call the mask in this field, correct?

    
asked by anonymous 02.10.2017 / 22:50

1 answer

1

There are two problems with your code:

  • Never import a lib and run JavaScript code inside it tag <script> .
  • Missing you close the call $(document).ready(function(){}) .
  • So, the code stays:

    <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="js/dist/jquery.mask.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
           $('.money2').mask("#.##0,00", {reverse: true});
        });
    </script>
    
        
    03.10.2017 / 03:22