Ejemplos en Javascript

Calculadora financiera

<HTML>
<HEAD>

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

<script language="JavaScript">

<!-- hide contents from old browsers

        var Cost, GST, PST, Grand_Total;

function tally()
        {
        Cost = 0;
        if (document.orderform.Item1.checked) { Cost = Cost + 26.15;    }
        if (document.orderform.Item2.checked) { Cost = Cost + 26.10;    }
        if (document.orderform.Item3.checked) { Cost = Cost + 26;               }
        if (document.orderform.Item4.checked) { Cost = Cost + 26;               }
        if (document.orderform.Item5.checked) { Cost = Cost + 26.44;    }
        if (document.orderform.Item6.checked) { Cost = Cost + 26.01;    }
        if (document.orderform.Item7.checked) { Cost = Cost + 26;               }
        if (document.orderform.Item8.checked) { Cost = Cost + 26;               }              
       if (document.orderform.Item9.checked) {  Cost = Cost + 25;               }

        GST = (Cost * 0.07);
        PST = (Cost * 0.07);
       
        Cost = dollar(Cost);
        GST = dollar(GST);
        PST = dollar(PST);
        Grand_Total = parseFloat(Cost) + parseFloat(GST) + parseFloat(PST);
        Grand_Total = dollar(Grand_Total);

        document.orderform.Total.value = "$" + Cost;
        document.orderform.GST.value = "$" + GST;
        document.orderform.PST.value = "$" + PST;
        document.orderform.GrandTotal.value = "$" + Grand_Total;
        }

function dollar (amount)
{
        amount = parseInt(amount * 100);
        amount = parseFloat(amount/100);
        if (((amount) == Math.floor(amount)) && ((amount - Math.floor (amount)) == 0))
        {
                amount = amount + ".00"
                return amount;
        }
        if ( ((amount * 10) - Math.floor(amount * 10)) == 0)
        {
                amount = amount + "0";
                return amount;
        }
        if ( ((amount * 100) - Math.floor(amount * 100)) == 0)
        {
                amount = amount;
                return amount;
        }
        return amount;  
}

//--></script>


</HEAD>

<BODY bgcolor="white">

<form method="post" name="orderform" action="mailto:" tppabs="mailto:">
<table width=340 border="0">
    <tr><td colspan="4">
<BR><INPUT TYPE="checkbox" Name="Item1" Value="Item1_chosen" onClick="tally()"> Item One ($26.15)
<BR><INPUT TYPE="checkbox" Name="Item2" Value="Item2_chosen" onClick="tally()"> Item Two  ($26.10)
<BR><INPUT TYPE="checkbox" Name="Item3" Value="Item3_chosen" onClick="tally()"> Item Three  ($26)
<BR><INPUT TYPE="checkbox" Name="Item4" Value="Item4_chosen" onClick="tally()"> Item Four  ($26)
<BR><INPUT TYPE="checkbox" Name="Item5" Value="Item5_chosen" onClick="tally()"> Item Five  ($26.44)
<BR><INPUT TYPE="checkbox" Name="Item6" Value="Item6_chosen" onClick="tally()"> Item Six  ($26.10)
<BR><INPUT TYPE="checkbox" Name="Item7" Value="Item7_chosen" onClick="tally()"> Item Seven  ($26)
<BR><INPUT TYPE="checkbox" Name="Item8" Value="Item8_chosen" onClick="tally()"> Item Eight  ($26)
<BR><INPUT TYPE="checkbox" Name="Item9" Value="Item9_chosen" onClick="tally()"> Item Nine  ($25)
    </td></tr>
<tr>
<td> Total<BR><INPUT TYPE="text" NAME="Total" value="$0" size="7"></td>
<td> Tax (7%): <INPUT TYPE="text" NAME="PST" value="$0"  size="6">
<BR>
Tax (7%): <INPUT TYPE="text" NAME="GST" value="$0"  size="6"></td>
</tr>
<tr>
<td> Grand Total<BR> <INPUT TYPE="text" NAME="GrandTotal" value="$0" size="8"></td>
</tr>

    <tr>
      <td>Company Name:<BR><input type="Text" name="Company" size="25" maxlength="40"></td>
    </tr>
    <tr>
      <td>First Name:<BR><input type="Text" name="FirstName" size="15"
      maxlength="20"></TD>
        <TD>Last Name:<BR><input type="Text" name="LastName" size="15" maxlength="20"></td>
    </tr>
    <tr>
      <td>Address:<BR><input type="Text" name="Street" size="25" maxlength="40"></td>
    </tr>
    <tr>
      <td>City<BR><input type="Text" name="City" size="20" maxlength="20"> </td>
      <td>Province/State:<BR><input type="Text" name="Province" size="20" maxlength="40"></td>
    </tr>
    <tr>
      <td>Country:<BR><input type="Text" name="Country" size="20" maxlength="20"></td>
      <td>Code:<BR><input type="Text" name="Code" size="9" maxlength="10"></td>
    </tr>
    <tr>
      <td>Phone:<BR><input type="Text" name="Area" size="3" maxlength="5"> <input type="Text" name="Phone"
      size="8" maxlength="10"></td>
      <td>Fax:<BR><input type="Text" name="AreaFax" size="3" maxlength="5"> <input type="Text"
      name="Fax" size="8" maxlength="10"></td>
    </tr>
    <tr>
      <td>Email:<BR><input type="Text" name="Email" size="25" maxlength="20"></td>
    </tr>
          <td colspan="4" height="3"></hr>
          </td>
        </tr>
      <!--/table-->
      </td>
      <td align="center">
        <input type="Submit" value="Send Application"><p>
        <input type="RESET" value="Reset Application">
        </td>
    </tr>
  </table>
</form>



</body>
</html>

Calculadoras