Ejemplos en Javascript

Presupuesto de gastos

<HTML>
<HEAD>

<TITLE>Ejemplos Javascript: ejemplo pr???¡ctico </TITLE>

<SCRIPT>

function dp(price)
{
   string = "" + price;
   number = string.length - string.indexOf('.');
   if (string.indexOf('.') == -1)
      return string + '.00';
   if (number == 1)
      return string + '00';
   if (number == 2)
      return string + '0';
   if (number > 3)
      return string.substring(0,string.length-number+3);
return string;
}

function calculate()
{
document.calcform.total1.value = dp((document.calcform.price1.value)*(document.calcform.quantity1.value))
document.calcform.total2.value = dp((document.calcform.price2.value)*(document.calcform.quantity2.value))
document.calcform.total3.value = dp((document.calcform.price3.value)*(document.calcform.quantity3.value))
document.calcform.total4.value = dp((document.calcform.price4.value)*(document.calcform.quantity4.value))
document.calcform.total5.value = dp((document.calcform.price5.value)*(document.calcform.quantity5.value))
document.calcform.total6.value = dp((document.calcform.price6.value)*(document.calcform.quantity6.value))
document.calcform.total7.value = dp((document.calcform.price7.value)*(document.calcform.quantity7.value))
document.calcform.total8.value = dp((document.calcform.price8.value)*(document.calcform.quantity8.value))
document.calcform.total9.value = dp((document.calcform.price9.value)*(document.calcform.quantity9.value))
document.calcform.total10.value = dp((document.calcform.price10.value)*(document.calcform.quantity10.value))

document.calcform.subtotal.value = dp(eval(document.calcform.total1.value) + eval(document.calcform.total2.value) + eval(document.calcform.total3.value) + eval(document.calcform.total4.value) + eval(document.calcform.total5.value) + eval(document.calcform.total6.value) + eval(document.calcform.total7.value) + eval(document.calcform.total8.value) + eval(document.calcform.total9.value) + eval(document.calcform.total10.value))

document.calcform.tax.value = dp((document.calcform.subtotal.value)*0.175)
document.calcform.total.value = dp((document.calcform.subtotal.value)*1.175)
}

</SCRIPT>


</HEAD>

<BODY bgcolor="white" onload="calculate">


<CENTER>

<FORM name="calcform" action="mailto:" tppabs="mailto:" method="post">

<TABLE cellpadding=2 border=2 cellspacing=2><TR><TD>QUANTITY</TD><TD>PRICE</TD><TD>TOTAL</TD></TR>

<TR>
<TD><INPUT type="text" name="quantity1" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="price1" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="total1"></TD>
</TR>

<TR>
<TD><INPUT type="text" name="quantity2" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="price2" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="total2"></TD>
</TR>

<TR>
<TD><INPUT type="text" name="quantity3" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="price3" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="total3"></TD>
</TR>

<TR>
<TD><INPUT type="text" name="quantity4" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="price4" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="total4"></TD>
</TR>


<TR>
<TD><INPUT type="text" name="quantity5" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="price5" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="total5"></TD>
</TR>


<TR>
<TD><INPUT type="text" name="quantity6" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="price6" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="total6"></TD>
</TR>


<TR>
<TD><INPUT type="text" name="quantity7" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="price7" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="total7"></TD>
</TR>


<TR>
<TD><INPUT type="text" name="quantity8" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="price8" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="total8"></TD>
</TR>


<TR>
<TD><INPUT type="text" name="quantity9" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="price9" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="total9"></TD>
</TR>


<TR>
<TD><INPUT type="text" name="quantity10" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="price10" ONCHANGE="calculate()"></TD>
<TD><INPUT type="text" name="total10"></TD>
</TR>


<TR><TD></TD><TD>SUBTOTAL</TD><TD><INPUT type="text" name="subtotal"></TD></TR>
<TR><TD></TD><TD>TAX - 17.5%</TD><TD><INPUT type="text" name="tax"></TD></TR>
<TR><TD></TD><TD>GRAND TOTALL</TD><TD><INPUT type="text" name="total"></TD></TR>
</TABLE><INPUT type="button" Value="PRESS FIRST to calculate the values" ONCLICK="calculate()"><BR><INPUT type="submit" Value="Then click this to SUBMIT"></form>


</body>
</html>

Calculadoras