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 4 of 4

Thread: tax form

  1. #1
    New to the CF scene
    Join Date
    May 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Post tax form

    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.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,081
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Code:
    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:-

    Code:
    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..

  • Users who have thanked Philip M for this post:

    gtaIV (05-01-2008)

  • #3
    New to the CF scene
    Join Date
    May 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,081
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    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}


  •  

    Posting Permissions

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