maskMoney(jquery) not displaying value correctly

Asked

Viewed 1,257 times

0

Good afternoon guys, I’m having a problem using the maskMoney plugin from jQuery. I am using the following statement before

<div style="float:left; width: 25%">
  <asp:Label ID="Label24" runat="server" Text="Valor Total: "></asp:Label>
  <asp:RequiredFieldValidator ID="rfvValTotalEnsinoSuperior"        runat="server" ErrorMessage="Valor Total: Campo obrigatório."            ControlToValidate="tbValorTotalEnsinoSuperior" Display="Dynamic"  Text="*" ValidationGroup="ParteReembolsoEnsinoSuperior" ForeColor="Red"  SetFocusOnError="True"></asp:RequiredFieldValidator>
  <br />
  <asp:TextBox ID="tbValorTotalEnsinoSuperior" Size="25%" runat="server" MaxLength="100" ReadOnly="True"></asp:TextBox>
  <br /><br />
</div>

$("[id*=tbValorTotalEnsinoSuperior]").maskMoney({ prefix: 'R$ ', thousands: '.', decimal: ',' });

E em minha função tenho:   
    $("[id*=tbValorTotalEnsinoSuperior]").maskMoney('mask',0.01);

But in Textbox he puts the value as R $ 1,00 instead of R $ 0,01

Anyone can help?

  • Your code seems to work normally. It may be something else influencing.

  • Try placing the value between comma quotes: $("[id*=tbValorTotalEnsinoSuperior]").val("0,01");

  • Try to change the culture of your application, maybe you are using different culture than en-BR.

  • The strange thing is that if in the mask I change the order of '.'(point) and ','(comma) it displays the correct value R$0.01 but with the comma in front it continues displaying R$1.00

1 answer

1

Try to change the method .val() by method .maskMoney('mask', 0.01);

Example:

$("[id*=tbValorTotalEnsinoSuperior]").maskMoney({ prefix: 'R$ ', thousands: '.', decimal: ',' });
$("[id*=tbValorTotalEnsinoSuperior]").maskMoney('mask', 0.01);

See the result:

$(function() {
  $("#currency").maskMoney({
    prefix: 'R$ ',
    thousands: '.',
    decimal: ','
  }).maskMoney('mask', 0.01);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-maskmoney/3.0.2/jquery.maskMoney.min.js"></script>
<input type="text" id="currency" />

Update:

Your code works perfectly with method .val();, see the result:

$(function() {

  $("#currency").maskMoney({
    prefix: 'R$ ',
    thousands: '.',
    decimal: ','
  });

  $("#currency").val(0.01);

  $("#currency").maskMoney('mask');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-maskmoney/3.0.2/jquery.maskMoney.min.js"></script>
<input type="text" id="currency" />

  • Vlw by the answer, but msm with these changes the textbox continues to display the value R $ 1,00 instead of R $ 0,01

  • @Philipematheus Puts your html code in your question.

  • ready, put the html

  • @Philipematheus You are using ASP.NET Web Forms ?

  • no, n is web Forms

Browser other questions tagged

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