Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JS calculator problem

    I am a newbie to js. I have a website that needs a web page which can calculate an individuals total tax burden for the year. The formula is very simple, but creating the functionality of the calculator seems to be quite the task due to my novice experience. There are 12 fields where the user inputs there annual tax information. Once the fields have been completed the user hits calculate and the script adds up the fields and inputs the value in the total tax field. I have conquered this part, but past this point I am stuck. There are two fields left that need to auto complete along with the total tax burden field and I can't seem to get it to work. Any help or referencing would be great.

    Calculator formula:

    TotalTax = Sum of all taxes = Items 2 -> Item 12

    Total Tax Burden = TotalTax / Income = shown as XX%

    Total Tax Burden Corparate = TTBurden + 20% = shown as XX%

    For example if Income (item 1) = $50,000
    TotalTax (item 12) = $7500

    Then when CALCULATE button is pressed, the following calculations are shown:

    Then Total Tax Burden = 7500/50000 = shown as 15%

    Total Tax Burden Corparate = 15% + 20% = shown as 35% (note: always add 20%).

    Here is my Code:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Tester</title>
    
    <script language="javascript">
    	function fadd(){
    		var one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,res;
    			//Take the value of first textbox and convert it to float
    			one   =parseFloat(document.forms[0].Income.value);
    			two   =parseFloat(document.forms[0].FedTax.value);
    			three =parseFloat(document.forms[0].SSTax.value);
    			four  =parseFloat(document.forms[0].WCTax.value);
    			five  =parseFloat(document.forms[0].SUTax.value);
    			six   =parseFloat(document.forms[0].FUTax.value);
    			seven =parseFloat(document.forms[0].PTaxH.value);
    			eight =parseFloat(document.forms[0].PTaxC.value);
    			nine  =parseFloat(document.forms[0].PTaxO.value);
    			ten   =parseFloat(document.forms[0].GasTax.value);
    			eleven=parseFloat(document.forms[0].OtherTax.value);
    			twelve=parseFloat(document.forms[0].SalesTax.value);
    			res=one+two+three+four+five+six+seven+eight+nine+ten+eleven+twelve;
    		
    			//show the result in the result textbox
    			document.forms[0].totalTax.value=res;
    		}
    
    </script>
    </head>
    
    <body>
    
    <form name="cal" method="post" action="">
    <table width="70%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td><div align="left">Enter your total ANNUAL INCOME:</div></td>
    <td><input name="Income" type="text" id="Income"></td>
    </tr>
    <tr>
    <td><div align="left">Enter your total FEDERAL TAXES paid:</div></td>
    <td><input name="FedTax" type="text" id="FedTax"></td>
    </tr>
    <tr>
    <td><div align="left">Enter your total SOCIAL SECURITY TAXES paid:</div></td>
    <td><input name="SSTax" type="text" id="SSTax"></td>
    </tr>
    <tr>
    <td><div align="left">Enter your total WORKERS COMP TAXES paid:</div></td>
    <td><input name="WCTax" type="text" id="WCTax"></td>
    </tr>
    <tr>
    <td><div align="left">Enter your total STATE UNEMPLOYEEMENT TAX paid:</div></td>
    <td><input name="SUTax" type="text" id="SUTax"></td>
    </tr>
    <tr>
    <td><div align="left">Enter your total FEDERAL UNEMPLOYEEMENT TAX paid:</div></td>
    <td><input name="FUTax" type="text" id="FUTax"></td>
    </tr>
    <tr>
    <td><div align="left">Enter your PROPERTY TAX paid on your house:</div></td>
    <td><input name="PTaxH" type="text" id="PTaxH"></td>
    </tr>
    <tr>
    <td><div align="left">Enter your PROPERTY TAX paid on your cars:</div></td>
    <td><input name="PTaxC" type="text" id="PTaxC"></td>
    </tr>
    <tr>
    <td><div align="left">Enter any OTHER PROPERTY TAXES paid:</div></td>
    <td><input name="PTaxO" type="text" id="PTaxO"></td>
    </tr>
    <tr>
    <td><div align="left">Enter the total GAS TAX paid:</div></td>
    <td><input name="GasTax" type="text" id="GasTax"></td>
    </tr>
    <tr>
    <td><div align="left">Enter any OTHER TAXES you paid:</div></td>
    <td><input name="OtherTax" type="text" id="OtherTax"></td>
    </tr>
    <tr>
    <td><div align="left">Enter the TOTAL SALES TAX paid:</div></td>
    <td><input name="SalesTax" type="text" id="SalesTax"></td>
    </tr>
    <tr>
    <td height="28"><div align="right">Total Tax Paid = $</div></td>
    <td height="28"><input name="totalTax" type="text" id="totalTax"></td>
    </tr>
    <tr>
    <td height="21"> <div align="left"></div></td>
    <td height="21"><input name="btnadd" type="button" id="btnadd" value="Calculate Total" onclick="fadd()"><input type="reset" name="" /></td>
    </tr>
    <tr>
    <td><strong>According to these figures your total tax burden for last year was:</strong></td>
    <td><input type="text" value="" name="TTBurden"  id="TTBurden" /></td>
    </tr>
    <tr>
    <td><strong>When you include corporate taxes and other hidden taxes, your total tax burden is closer to:</strong></td>
    <td><input type="text" value="" name="TTBCorp" id="TTBCorp"  /></td>
    </tr>
    </table>
    </form>
    </center>
    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,501
    Thanks
    3
    Thanked 500 Times in 487 Posts
    this would have been best on the main javascript forum but

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Tester</title>
    
    <script language="javascript">
    function fadd(){
     var one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,res;
     var frm=document.forms[0];
     var fldary=['FedTax','SSTax','WCTax','SUTax','FUTax','PTaxH','PTaxC','PTaxO','GasTax','OtherTax','SalesTax'];
     var total=0;
     for (var zxc0=0;zxc0<fldary.length;zxc0++){
      if (!parseFloat(frm[fldary[zxc0]].value)) frm[fldary[zxc0]].value='0';
      total+=frm[fldary[zxc0]].value*1;
     }
    //show the result in the result textbox   TTBurden
     frm.totalTax.value=total;
     if (!parseFloat(frm.Income.value)) frm.Income.value='0';
     var tax=(total/frm.Income.value)*100||0;
     frm.TTBurden.value=(tax>0?tax:0)+'%';
     frm.TTBCorp.value=(tax>0?tax+20:0)+'%';
    
    }
    
    </script>
    </head>
    
    <body>
    
    <form name="cal" method="post" action="">
    <table width="70%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td><div align="left">Enter your total ANNUAL INCOME:</div></td>
    <td><input name="Income" type="text" id="Income"></td>
    </tr>
    <tr>
    <td><div align="left">Enter your total FEDERAL TAXES paid:</div></td>
    <td><input name="FedTax" type="text" id="FedTax"></td>
    </tr>
    <tr>
    <td><div align="left">Enter your total SOCIAL SECURITY TAXES paid:</div></td>
    <td><input name="SSTax" type="text" id="SSTax"></td>
    </tr>
    <tr>
    <td><div align="left">Enter your total WORKERS COMP TAXES paid:</div></td>
    <td><input name="WCTax" type="text" id="WCTax"></td>
    </tr>
    <tr>
    <td><div align="left">Enter your total STATE UNEMPLOYEEMENT TAX paid:</div></td>
    <td><input name="SUTax" type="text" id="SUTax"></td>
    </tr>
    <tr>
    <td><div align="left">Enter your total FEDERAL UNEMPLOYEEMENT TAX paid:</div></td>
    <td><input name="FUTax" type="text" id="FUTax"></td>
    </tr>
    <tr>
    <td><div align="left">Enter your PROPERTY TAX paid on your house:</div></td>
    <td><input name="PTaxH" type="text" id="PTaxH"></td>
    </tr>
    <tr>
    <td><div align="left">Enter your PROPERTY TAX paid on your cars:</div></td>
    <td><input name="PTaxC" type="text" id="PTaxC"></td>
    </tr>
    <tr>
    <td><div align="left">Enter any OTHER PROPERTY TAXES paid:</div></td>
    <td><input name="PTaxO" type="text" id="PTaxO"></td>
    </tr>
    <tr>
    <td><div align="left">Enter the total GAS TAX paid:</div></td>
    <td><input name="GasTax" type="text" id="GasTax"></td>
    </tr>
    <tr>
    <td><div align="left">Enter any OTHER TAXES you paid:</div></td>
    <td><input name="OtherTax" type="text" id="OtherTax"></td>
    </tr>
    <tr>
    <td><div align="left">Enter the TOTAL SALES TAX paid:</div></td>
    <td><input name="SalesTax" type="text" id="SalesTax"></td>
    </tr>
    <tr>
    <td height="28"><div align="right">Total Tax Paid = $</div></td>
    <td height="28"><input name="totalTax" type="text" id="totalTax"></td>
    </tr>
    <tr>
    <td height="21"> <div align="left"></div></td>
    <td height="21"><input name="btnadd" type="button" id="btnadd" value="Calculate Total" onclick="fadd()"><input type="reset" name="" /></td>
    </tr>
    <tr>
    <td><strong>According to these figures your total tax burden for last year was:</strong></td>
    <td><input type="text" value="" name="TTBurden"  id="TTBurden" /></td>
    </tr>
    <tr>
    <td><strong>When you include corporate taxes and other hidden taxes, your total tax burden is closer to:</strong></td>
    <td><input type="text" value="" name="TTBCorp" id="TTBCorp"  /></td>
    </tr>
    </table>
    </form>
    </center>
    </body>
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks VWphillips, you really help me out. I've been battling with that script for a while and it was so simple.

    Sorry about not placing this in the right forum. I'll get it right next time.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •