[Resolvido] Somar valores e formatar campos
Fiz um formulário onde o usuario vai digitar a quantidade de um produto e ele irá somar o valor total baseado no valor unitário.
Agora tentei um incluir um campo no final que irá somar os valores totais de todos os procutos... Esse campo está somando, mas não está formatandoo campo o valor fica assim por exemplo: 15.190000 e o correto seria ficar 15.20
Meu codigo:
> <script> function soma1(){
sa = document.getElementById("qtde1").value;
sb = document.getElementById("vlr1").value;
rsa = sa*sb;
vss = rsa.toFixed(2);
document.getElementById("total1").value = vss;
}
function soma2(){
sa = document.getElementById("qtde2").value;
sb = document.getElementById("vlr2").value;
rsa = sa*sb;
vss = rsa.toFixed(2);
document.getElementById("total2").value = vss;
}
function somatotal()
{
somatudo = (form.total1.value*1) + (form.total2.value*1);
somatudogeral = somatudo.toFixed(2);
document.getElementById("totalgeral").value = somatudo;
}
</script>
E o html
> <form name="form"> <table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150" height="50"><strong>Quantidade:</strong><br />
<input name="qtde1" type="text" class="campoform1" id="qtde1" style="height:20px; width:80px;" onkeyup="soma1();somatotal();" value="2" /></td>
<td width="210"><strong>Valor Unitario:</strong><br />
<input name="vlr1" type="text" class="campoform1" id="vlr1" style="height:20px; width:110px;" value="2.00" disabled="disabled" /></td>
<td width="140"><strong>Total:</strong><br />
<input name="total1" type="text" class="campoform1" id="total1" style="height:20px; width:80px;" value="4.00" /></td>
</tr>
<tr>
<td height="40"><input name="qtde2" type="text" class="campoform1" id="qtde2" style="height:20px; width:80px;" onkeyup="soma2();somatotal();" value="1" /></td>
<td><input name="vlr2" type="text" class="campoform1" id="vlr2" style="height:20px; width:110px;" value="2.53" disabled="disabled" /></td>
<td><input name="total2" type="text" class="campoform1" id="total2" style="height:20px; width:80px;" value="2.53" /></td>
</tr>
<tr>
<td height="40"> </td>
<td> </td>
<td><input name="totalgeral" type="text" id="totalgeral" style="height:20px; width:80px;" value="6,53" /></td>
</tr>
</table>
</form>Discussão (6)
Carregando comentários...