Convert Number in Reais

1

I want to develop an example simulator: from 1 to 99 real multiplies it by x10 and strong> real it multiplies by x11 .

I wanted to know how to convert the number of campo1 to real when typing?

Code:

<html>
   <body>
       <head>

       </head>
<script> 
function soma() 
{
form.campo4.value = (form.campo1.value*1) * (form.campo2.value*1)
$('form.campo1').priceFormat({
    prefix: 'R$ ',
    centsSeparator: ',',
    thousandsSeparator: '.'
});
}
</script>
<form name="form">
    <p> Simulador de Cash's</p>
<input name="campo1" type="text" value="" class="soma"><br> 
<input name="campo2" value="22" readonly><br> 
<input name="campo4" readonly><br>
<input type="button" onclick="soma()" value="CALCULAR">
</form>
 </body>
</html>
    
asked by anonymous 02.09.2017 / 16:57

2 answers

2

I suggest a jQuery plugin called maskMoney ( download here ). It adds currency mask to the field you specify.

To use it, click on its page with:

<script src="jquery.maskMoney.js" type="text/javascript"></script>

And call the plugin with the script:

$(function(){
 $("input").maskMoney({symbol:'R$ ', 
showSymbol:false, thousands:'.', decimal:',', symbolStay: true});
 });

A good tutorial on how to use the plugin.

Fiddle to test.

    
02.09.2017 / 17:50
0

I got the link right here when I'm going to multiply Ta giving NaN because:?

<html>
   <body>
   <script src="jquery.min.js" type="text/javascript"></script>
    <script src="jquery.maskMoney.js" type="text/javascript"></script>
<script> 
function soma() 
{
form.campo4.value = (form.campo1.value*1) * (form.campo2.value*1) 
}
</script>
<script type="text/javascript">
$(function(){
 $("#demo4").maskMoney({symbol:'R$ ', 
showSymbol:true, thousands:'.', decimal:',', symbolStay: true});
 })
</script>
<form name="form">
<input name="campo1" id="demo4"><br> 
<input name="campo2" value="22" id="demo3"><br>  
<input name="campo4" readonly><br>
<input type="button" onclick="soma()" value="Soma os Valores">
</form>
   </body>
</html>

the code tests on your machine for you to see

    
02.09.2017 / 16:59