...

View Full Version : tax form



gtaIV
05-01-2008, 08:08 AM
Hi guys, i am making a form that works out annual salary, annual tax etc and im having a little trouble with the code.

<script>
function calculate() {
var week = parseInt (document.tform.ws.value)
var salary = parseInt (document.tform.as.value)
var tax = parseInt (document.tform.at.value)
var levy = parseInt (document.tform.ml.value)
var amount = parseInt (document.tform.ma.value)

week = ws * 52
salary = week
tax = ws * 0.3
levy = ws * 0.15
amount = at + ml

if (week >=)
document.write
else if (salary >=)
document.write
else if (tax >=)
document.write
else if (levy >=)
document.write
else
document.write



}


</script>

that is what i have so far, we have to work it out with if statements only. any tips would be much appreciated.

Philip M
05-01-2008, 08:21 AM
function calculate() {
var week = parseInt (document.tform.ws.value)
var salary = parseInt (document.tform.as.value)
var tax = parseInt (document.tform.at.value)
var levy = parseInt (document.tform.ml.value)
var amount = parseInt (document.tform.ma.value)

week = ws * 52
salary = week
tax = ws * 0.3
levy = ws * 0.15
amount = at + ml
You have defined the variables week, salary, tax etc.
I don't understand var amount = parseInt (document.tform.ma.value)


So you want something like:-


salary = week * 52; // i.e. 52 weeks' salary
tax = salary * 0.3; // 30&#37; tax
levy = salary * 0.15; // 15% levy
amount = salary - tax - levy // net annual pay You should avoid giving your variables ambiguous names such as "amount" or "salary". Use something meaningful instead such as "weekSalary" or "totalPayable"



Quizmaster: Which surname was shared by a historical outlaw called "Butch" and a fictional cowboy called "Hopalong"?
Contestant: Lesbian..

gtaIV
05-01-2008, 08:30 AM
Thanks for the info, im just alittle confused on how i inforce it into the if, else if statements. Does the code i have at the moment look right?

Philip M
05-01-2008, 08:39 AM
Well, it is not very obvious what you are trying to achieve. So far I do not see any conditions. You are simply taking the week salary, multiplying by 52 to get annual salary, working out tax and levy and deducting these from annual salary.

But the general form of an if-else statement is

if (testExpression) { do this}
else {do that}

so for example:

if (salary <= 10000) {tax = salary * .1)}
else {tax = salary * .3}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum