I am unable to run the monetary mask by Jquery

Asked

Viewed 107 times

0

I am trying to configure my inputs with 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 have also tried to replace $('.money2') with $('#cr11') in trying to call by id.

In both cases (class or id) did not work, as can be seen from the image below. inserir a descrição da imagem aqui I should call the mask in this field already, correct?

  • Which is the mask plugin you are using ? Jquery inputmask or other ? sends the link from where you downloaded it here in the comment

  • Check that scripts are being loaded normally. Press F12 and see that the browser does not show any errors. Taking advantage, I used your code in this fiddle and the same is working normally.

  • Hello Anthraxisbr, I downloaded the following link: https://github.com/igorescobar/jQuery-Mask-Plugin/archive/master.zip

  • Hello Randrade, this code appears on the console : Xmlhttprequest synchronous should not be used on the main thread due to its harmful effects on the user experience. For more information http://xhr.spec.whatwg.org/ (jquery-3.2.1.min. js:4:15845)

  • I can’t seem to solve friends...

1 answer

1


You have two problems with your code:

  1. Never import a lib and run Javascript code within it tag <script>.
  2. Missed 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>
  • Perfect Lucas. Thank you very much.

Browser other questions tagged

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