/    Sign up×
Community /Pin to ProfileBookmark

Calculated Field

Hello All, Your help is greatly appreciated

I have a form that i am using to enter payroll data…

Field Hours {=====}
Field PayRate {=====}

Field Total Hours {=====} I used a javascript to calculate total hours

Field GrossWages {=====} I used a javascript to calculate total wages

I need help calculating some tax values, and have the Field Tax Calculate before I submit the form:

Here are the specs for the tax:

  • 1. apply 10% if varMartialStatus=SINGLE and GrossWages is between 51 and 195
  • 2 apply 10% if varMartialStatus=MARRIED and GrossWages is between 154 and 449

  • 3. apply 15% if varMartialStatus=SINGLE and GrossWages is between 195 and 645
  • 4 apply 15% if varMartialStatus=MARRIED and GrossWages is between 449 and 1360

    to post a comment
    JavaScript

    3 Comments(s)

    Copy linkTweet thisAlerts:
    @JMRKERJul 16.2008 — Post your code for help.

    Include your requirements when it doesn't work as expected.
    Copy linkTweet thisAlerts:
    @MarvinSkauthorJul 16.2008 — <i>
    </i>
    &lt;HEAD&gt;
    &lt;script language="JavaScript" type="text/javascript"&gt;
    function compute() {

    If (varMartialStatus == SINGLE) {
    If (GrossWages &lt; 51) Tax = 0
    Else If (GrossWages &gt;= 51 &amp;&amp; &lt; 195) Tax = 0.10
    Else If (GrossWages &gt;= 195 &amp;&amp; &lt; 645) Tax = 0.15
    Else Tax = 0
    }
    else {
    If (GrossWages &lt; 154) Tax = 0
    Else If (GrossWages &gt;= 154 &amp;&amp; &lt; 449) Tax = 0.10
    Else If (GrossWages &gt;= 449 &amp;&amp; &lt; 1360) Tax = 0.15
    Else Tax = 0
    }

    }

    &lt;/script&gt;
    &lt;/HEAD&gt;

    &lt;BODY&gt;

    &lt;center&gt;
    &lt;form name=paycheck&gt;
    &lt;table border=1&gt;
    &lt;!--DWLayoutTable--&gt;
    &lt;tr&gt;
    &lt;td width="48" height="26" valign="top"&gt;&lt;input name=fldMartial type=text id="fldMartial" size=8 value="0"&gt;&lt;/td&gt;
    &lt;td width="219"&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;td height="26" valign="top"&gt;&lt;input name=fldGrossWages type=text id="fldGrossWages" size=8 value="55" onChange="compute()"&gt;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;td height="26" valign="top"&gt;&lt;input name=fldFedTax type=text id="fldFedTax" size=8&gt;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;td height="26" valign="top"&gt;&lt;input name=fldTotNetWages type=text id="fldTotNetWages" size=8&gt;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;/table&gt;
    &lt;/form&gt;
    &lt;/center&gt;
    Copy linkTweet thisAlerts:
    @JMRKERJul 16.2008 — I see several problems that might lead to poor performance:

  • 1. There are no 'If', only 'if' statements

  • 2. There are no 'Else', only 'else' statements

  • 3. The syntax of the 'if (condiition) { doTrueStuff} else { doFalseStuff } etc. is incorrect.

  • 4. The references do not match, ie; where does 'varMaritalStatus' come from?

  • 5. The condition comparisons should be (??? just a guess ???)

    if (document.form.fldMartial.value == 'SINGLE') { ..... }

  • 6. The comparisons should be in quotes (single ' or double ")


  • Might want to check the error console for other problems after these fixes.
    ×

    Success!

    Help @MarvinSk spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.3,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...