How do I make a mask that adapts to priced inputs?

Asked

Viewed 46 times

-5

I was using Jquery but how do I adapt to put 2 numbers insert a ',' this way but would be necessary to put 4 values, and I do not know the exact price that would be

$('[formato=price]').mask('9999,99');

1 answer

-2


Maybe it’s not the expected solution anymore it’s the best to be done.

In your case I would recommend using the plugin Jquery Maskmoney, This little plug already comes in the way to format fields for money according to your needs, plus some pretty cool options. You can access the latest version of this minified plugin by clicking here

Or use via Cdn including in your code: <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-maskmoney/3.0.2/jquery.maskMoney.min.js"></script>

Final solution was like this:

HTML

<form action="">
  <input type="text" class="ValoresItens" id="ValoresItens">
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-maskmoney/3.0.2/jquery.maskMoney.min.js"></script>

JS

$(".ValoresItens").maskMoney({
             prefix: "R$:",
             decimal: ",",
             thousands: "."
         });
     

Final result can be seen in : inserir a descrição da imagem aqui

  • I wanted to make an input for item prices and wanted that when putting 2 numbers in the input was inserted a comma symbolizing cents and then would be typed the dozens, for example in the marketplace that I believe has the same system to put price in your ads

  • 1

    Right. Thank you very much for the information, but sometimes it’s hard to give a good answer by not having a good question. I edited the answer and improved it in the best way possible. if you have solved your problem communicate.

Browser other questions tagged

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