PDA

View Full Version : Tax Calculator code not working



mio77787
Apr 2nd, 2007, 04:10 PM
Hi,

I am attempting to build a tax calculator to provide to users of my website.

The calculator basically uses the following 4 rules ...

// The first 5225 of a person's salary = no tax is charged
// The next 2320 of a person's salary = 10% tax charged
// The next 27055 of a person's salary = 22% tax charged
// The next part of their salary = 40% tax charged

... and this is clarified in the pseudo code:

/// If a salary is under 5225
/ activate function bracket1()
/ 1st tax to be charged on the first 5225 = 0%
/ net salary is (salary - 1st tax)

/// If a salary is under 7545
/ activate function bracket2()
/ 1st tax to be charged on the first 5225 = 0%
/ 2nd tax to be charged on the remainder = 10%
/ net salary is (salary - (1st tax + 2nd tax)

/// If a salary is under 34600
/ activate function bracket3()
/ 1st tax to be charged on the first 5225 = 0%
/ 2nd tax to be charged on the next 2320 = 10%
/ 3rd tax to be charged on the remainder = 22%
/ net salary is (salary - (1st tax + 2nd tax + 3rd tax)

/// If a salary is over 34600
/ activate function bracket4()
/ 1st tax to be charged on the first 5225 = 0%
/ 2nd tax to be charged on the next 2320 = 10%
/ 3rd tax to be charged on the next 27055 = 22%
/ 4th tax to be charged on the remainder = 40%
/ net salary is (salary - (1st tax + 2nd tax + 3rd tax + 4th tax)


Below is my javascript. Now I know that it is not advisable to put the whole code in the thread, but the reason I have put it down here is simply because I have no clue where the error is.

Once I enter in the Salary (which is denoted as GrossText in the code below, I am suppose to press the tab button and the net salries should appear in the remaining fields. This was working when the code was simple (and had incorrect tax rates). Now that I have completed building it simply does nothing. No answers are displayed in the relevant boxes. They simply remain blank like nothing has happened.

Please Help!!

// The code

<html>

<head>

<script>

<!-- Begin


function TotalGrossPerYear() {

var Calc = document.NetIncome;

if (!(Calc.GrossText.value < 5225))
{
Bracket1();
}

else {
if (!(Calc.GrossText.value < 7545))
{
Bracket2();
}
}

else {
if (!(Calc.GrossText.value < 34600))
{
Bracket3();
}
}

else {
if (!(Calc.GrossText.value > 34600))
{
Bracket4();
}
}

}



function Bracket1() {
var Calc = document.NetIncome;
Calc.NetText.value = (parseFloat(Calc.GrossText.value) - 5225) + " ";

Calc.MonthlyText.value = Math.round(parseFloat(Calc.NetText.value) / 12.991) + " ";
Calc.Bi_WeeklyText.value = (parseFloat(Calc.MonthlyText.value) / 2) + " ";
Calc.WeeklyText.value = (parseFloat(Calc.Bi_WeeklyText.value) / 2) + " ";
}



function Bracket2() {
var Calc = document.NetIncome;
Calc.GH1Text.value = (parseFloat(Calc.GrossText.value) - 5225) + " ";
Calc.GH2Text.value = ((parseFloat(Calc.GH1Text.value)) * (10 / 100)) + " ";
Calc.NetText.value = (parseFloat(Calc.GrossText.value) - parseFloat(Calc.GH2Text.value)) + " ";

Calc.MonthlyText.value = Math.round(parseFloat(Calc.NetText.value) / 12.991) + " ";
Calc.Bi_WeeklyText.value = (parseFloat(Calc.MonthlyText.value) / 2) + " ";
Calc.WeeklyText.value = (parseFloat(Calc.Bi_WeeklyText.value) / 2) + " ";
}



function Bracket3() {
var Calc = document.NetIncome;
Calc.GH1Text.value = (parseFloat(Calc.GrossText.value) - 5225) + " ";
Calc.GH2Text.value = (parseFloat(2320) * (10 / 100)) + " ";
Calc.GH3Text.value = (parseFloat(Calc.GH1Text.value) - 2320) + " ";
Calc.GH4Text.value = ((parseFloat(Calc.GH3Text.value)) * (22 / 100)) + " ";
Calc.NetText.value = (parseFloat(Calc.GrossText.value) - (parseFloat(Calc.GH2Text.value) + parseFloat(Calc.GH4Text.value))) + " ";

Calc.MonthlyText.value = Math.round(parseFloat(Calc.NetText.value) / 12.991) + " $";
Calc.Bi_WeeklyText.value = (parseFloat(Calc.MonthlyText.value) / 2) + " $";
Calc.WeeklyText.value = (parseFloat(Calc.Bi_WeeklyText.value) / 2) + " $";
}



function Bracket4() {
var Calc = document.NetIncome;
Calc.GH1Text.value = (parseFloat(Calc.GrossText.value) - 5225) + " ";
Calc.GH2Text.value = (parseFloat(2320) * (10 / 100)) + " ";
Calc.GH3Text.value = (parseFloat(27055) * (22 / 100)) + " ";
Calc.GH4Text.value = ((parseFloat(Calc.GH1Text.value)) - (2320 + 27055)) + " ";
Calc.GH5Text.value = ((parseFloat(Calc.GH4Text.value)) * (40 / 100)) + " ";
Calc.NetText.value = (parseFloat(Calc.GrossText.value) - (parseFloat(Calc.GH2Text.value) + parseFloat(Calc.GH3Text.value) + parseFloat(Calc.GH5Text.value))) + " ";

Calc.MonthlyText.value = Math.round(parseFloat(Calc.NetText.value) / 12.991) + " $";
Calc.Bi_WeeklyText.value = (parseFloat(Calc.MonthlyText.value) / 2) + " $";
Calc.WeeklyText.value = (parseFloat(Calc.Bi_WeeklyText.value) / 2) + " $";
}



function NAGrossText() {
var Calc = document.NetIncome;
Calc.GrossText.value = "N/A";
}
// End -->
</script>

</head>

<body>


<form method=post name=NetIncome>

<input type=hidden name=GH1Text size=10>
<input type=hidden name=GH2Text size=10>
<input type=hidden name=GH3Text size=10>
<input type=hidden name=GH4Text size=10>
<input type=hidden name=GH5Text size=10>

<table border=5>

<th align=left>
<ol>
<li>Choose Hourly or Yearly format.
<li>Fill out the form, skipping N/A fields.
<li>Press the TAB key when finished.
</ol>
</th>

<tr><td><input type=text name=GrossText size=10 onChange="TotalGrossPerYear()">Total Gross per year </td></tr>
<tr><td><input type=text name=NetText size=10 value="-------">Total Net income</td></tr>
<tr><td><input type=text name=MonthlyText size=10 value="-------">Total Monthly Net</font></td></tr>
<tr><td><input type=text name=Bi_WeeklyText size=10 value="-------">Total bi-weekly Net</td></tr>
<tr><td><input type=text name=WeeklyText size=10 value="-------">Total Weekly Net</td></tr>
<tr><td align=center><input type=reset Value="Reset Form"></td></tr>

</table>

</form>

Read the <a href="javascript:void(0);" onClick="alert('This assumes you are working 40 hours a week (2080 a year)\nunless you enter your own hours. This script is compliant\nwith the 1997 Income-tax Standard. However, it may vary\nslightly. Please do not use these results as your quote.');">fine print</a>

</body>

Arty Effem
Apr 2nd, 2007, 08:54 PM
if (!(Calc.GrossText.value < 5225))
{
Bracket1();
}

else {
if (!(Calc.GrossText.value < 7545))
{
Bracket2();
}
}

else {
Didn't they teach you to use the console?

Even the I.E. console makes this problem clear.

Don't drive with your eyes closed.