Money Values

[Total: 0    Average: 0/5]

This will show how to compute cost given quantity, price, and tax.

Head Code:

<SCRIPT>
<!-- Activate Cloaking Device 

// Called by computeIt() function - creates $xx.xx format.
function fmtPrice(value)
   {
   result="$"+Math.floor(value)+".";
   var cents=100*(value-Math.floor(value))+0.5;
   result += Math.floor(cents / 10);
   result += Math.floor(cents % 10);
   return result;
   }

// Called by COMPUTE button - gathers selected values, computes tax & total cost, displays values. 
function computeIt(form) 
   {
   // Sets myindex1 to selected value from unit menu.
   var myindex1 = form.unit.selectedIndex;
   // Sets myindex2 to selected value from cost menu.
   var myindex2 = form.cost.selectedIndex;
   // Sets myindex3 to selected value from tax menu.
   var myindex3 = form.tax.selectedIndex;

   // Checks that an item is selected from each menu.
   if (myindex1>=1 && myindex2>=1 && myindex3>=1)
      {
      // Variables used for computations.
      var units = form.unit.options[myindex1].value;
      var cost  = form.cost.options[myindex2].value;
      var tax    = form.tax.options[myindex3].value;
      // Computations
      var unit_cost = units * cost;
      var tax_cost  = unit_cost * tax;
      var total_cost = eval( unit_cost )  + eval( tax_cost );
      // Display formatted values.
      form.display_cost.value = fmtPrice(unit_cost);
      form.display_tax.value = fmtPrice(tax_cost);
      form.display_total.value = fmtPrice(total_cost);
      }
   // Displays an Alert message if a selection is not made from both menus.
   else
      alert("nYou must first select nn    - the number of UNITSnn    - a COST per unitnn    - the applicable TAXnn before clicking the COMPUTE button.");
   }

// Deactivate Cloaking -->
</SCRIPT>

Body Code:

<FORM NAME="myform">
<TABLE BORDER=3 WIDTH=450>
<TR>
<TD align="center">UNITS
<TD align="center">COST
<TD align="center">TAX
</TR><TR>
<TD align="center"><SELECT NAME="unit" SIZE=1>
    <OPTION SELECTED VALUE="">**********
    <OPTION VALUE="1">1
    <OPTION VALUE="2">2
    <OPTION VALUE="3">3
    <OPTION VALUE="4">4
    <OPTION VALUE="5">5
    <OPTION VALUE="6">6
    <OPTION VALUE="7">7
    <OPTION VALUE="8">8
    <OPTION VALUE="9">9
    <OPTION VALUE="10">10
  </SELECT>
<TD align="center"><SELECT NAME="cost" SIZE=1>
    <OPTION SELECTED VALUE="">**********
    <OPTION VALUE="5">$05.00
    <OPTION VALUE="10">$10.00
    <OPTION VALUE="15">$15.00
    <OPTION VALUE="20">$20.00
    <OPTION VALUE="25">$25.00
    <OPTION VALUE="30">$30.00
    <OPTION VALUE="35">$35.00
    <OPTION VALUE="40">$40.00
    <OPTION VALUE="45">$45.00
    <OPTION VALUE="50">$50.00
  </SELECT>
<TD align="center"><SELECT NAME="tax" SIZE=1>
    <OPTION SELECTED VALUE="">**********
    <OPTION VALUE=".01">1%
    <OPTION VALUE=".02">2%
    <OPTION VALUE=".03">3%
    <OPTION VALUE=".04">4%
    <OPTION VALUE=".05">5%
    <OPTION VALUE=".06">6%
    <OPTION VALUE=".07">7%
    <OPTION VALUE=".08">8%
    <OPTION VALUE=".09">9%
    <OPTION VALUE=".10">10%
  </SELECT>
</TR></TABLE>
<BR><BR>
<TABLE BORDER=4 WIDTH=500>
<TR>
<TD align="center">COST
<TD align="center">TAX
<TD align="center">TOTAL
</TR><TR>
<TD align="center"><INPUT TYPE="text" NAME="display_cost" SIZE=10>
<TD align="center"><INPUT TYPE="text" NAME="display_tax" SIZE=10>
<TD align="center"><INPUT TYPE="text" NAME="display_total" SIZE=10>
</TR>
</TABLE>
<BR>
<TABLE BORDER=0 WIDTH=460>
<TD align="center"><INPUT TYPE="reset" VALUE=" Reset ">
<TD align="center"><INPUT TYPE="button" VALUE="COMPUTE" onClick="computeIt(this.form)">
<TD align="center"><INPUT TYPE="button" VALUE=" About " onClick="about()">
</TABLE>
<BR><BR>
</FORM>

Times Viewed: 5

Leave a Reply

Your email address will not be published. Required fields are marked *