/    Sign up×
Community /Pin to ProfileBookmark

Calculation Formulas

I have a basic salary calculator script that I am trying to modify to my needs, and while I have some basic knowledge of Javascript, this is a tad beyond me and would greatly appreciate any assistance any one would provide.

Here is the code:

<!– TWO STEPS TO INSTALL SALARY CALCULATOR:

  • 1.

    Copy the coding into the HEAD of your HTML document

  • 2.

    Add the last code into the BODY of your HTML document –>

  • <!– STEP ONE: Paste this code into the HEAD of your HTML document –>

    <HEAD>

    <SCRIPT LANGUAGE=”JavaScript”>

    <!– Begin

    function hourToYear(numHour){

    if(!numHour) {

    alert(“Please enter an hourly amount.”);

    return;

    }

    if(isNaN(numHour)){

    alert(numHour + ” is an invalid input. Please try again.”);

    return;

    }

    perWeek = numHour * 40

    perMonth = perWeek * 4

    perYear = perMonth * 12

    salaryForm.answerHour.value=”$” + toCurrency(numHour.toString());

    salaryForm.answerWeek.value=”$” + toCurrency(perWeek.toString());

    salaryForm.answerMonth.value=”$” + toCurrency(perMonth.toString());

    salaryForm.answerYear.value=”$” + toCurrency(perYear.toString());

    }

    function yearToHour(numYear){

    if(!numYear) {

    alert(“Please enter a yearly amount.”);

    return;

    }

    if(isNaN(numYear)){

    alert(numYear + ” is an invalid input. Please try again.”);

    return;

    }

    perMonth = numYear / 12

    perWeek = perMonth / 4

    perHour = perWeek / 40

    salaryForm.answerYear.value=”$” + toCurrency(numYear.toString());

    salaryForm.answerMonth.value=”$” + toCurrency(perMonth.toString());

    salaryForm.answerWeek.value=”$” + toCurrency(perWeek.toString());

    salaryForm.answerHour.value=”$” + toCurrency(perHour.toString());

    }

    function toCurrency(num) {

    num = Math.round(num*100)/100

    return num.toString();

    }

    // End –>

    </script>

    </HEAD>

    <!– STEP TWO: Copy this code into the BODY of your HTML document –>

    <BODY>

    <form name=”salaryForm” method=”post”>

    <table>

    <tr><td>Enter the <b>hourly</b> amount here:</td>

    <td><input name=”numHour” type=”INT” size=10 value=”0″></td>

    <td><input name=”ComputeHour” value=”Compute” type=”BUTTON”

    Onclick = “hourToYear(salaryForm.numHour.value)”><td>

    </tr>

    <tr>

    <td>OR</td>

    </tr>

    <tr><td>Enter the <b>yearly</b> amount here:</td>

    <td><input name=”numYear” type=”INT” size=10 value=”0″></td>

    <td><input name=”ComputeYear” value=”Compute” type=”BUTTON”

    Onclick = “yearToHour(salaryForm.numYear.value)”></td>

    </tr>

    <tr><td colspan=”3″><hr></td></tr>

    <tr><td>Yearly:</td><td><input name=”answerYear” type=”INT” value=”0″></td></tr>

    <tr><td>Monthly:</td><td><input name=”answerMonth” type=”INT” value=”0″></td></tr>

    <tr><td>Weekly:</td><td><input name=”answerWeek” type=”INT” value=”0″></td></tr>

    <tr><td>Hourly:</td><td><input name=”answerHour” type=”INT” value=”0″></td></tr>

    </table>

    </form>

    What I need is for an employer to be able to obtain the cost for “x” number of people to receive flu shots. This would use a preset rate chart : Less 10 = $40 per person, 11 – 25 = $35 per person, 26 – 50 =$30 per person, 51 + = $25 per person.

    Ideally, I would like the employer to just have to input the number of employees and click a Calculate Button and have the cost displayed in a form field. Ex. so if there were 7 emp. it would have to display the exact cost for 7 employees at $40 per emp. or 17 emp. calculated at $35 per emp. etc.

    Any help and guidance is greatly appreciated.

    Thank You Very Much.
    Michelle

    to post a comment
    JavaScript

    3 Comments(s)

    Copy linkTweet thisAlerts:
    @MjhLkwdOct 20.2005 — [CODE]<HTML>
    <Head>
    <Script type="text/javascript">

    function calcCost(nForm){

    var cost = 0;
    var n = nForm.nEmp.value;
    if (n <=10){cost = n*40}
    else if (n > 10 && n < 26){cost = n*35}
    else if (n > 25 && n < 51){cost = n*30}
    else {cost = n*25}
    nForm.nCost.value = cost+".00";
    }

    </Script>
    </Head>
    <Body>
    <Form name='fluCost'>
    # Employees: <input type='text' name='nEmp' size='3' onclick="this.value='';this.form.nCost.value=''"><br>
    Flu Shot Cost: $<input type='text' name='nCost' size='8' readonly>
    <br><br>
    <input type='button' value='Calculate' onclick="calcCost(this.form)">
    </Form>
    </Body>
    </HTML>[/CODE]
    Copy linkTweet thisAlerts:
    @smokywebauthorOct 20.2005 — ? ? ?

    Oh MY gosh! You are INCREDIBLE! A GENIUS! I am humble before you! Thank you so much Mike! I am so happy I am tingling ALL OVER. All thanks to you! You have been a tremendous help. I am eternally greatful! I hope to one day assist you.

    Thanks Again!

    Michelle
    Copy linkTweet thisAlerts:
    @MjhLkwdOct 20.2005 — Michelle,

    You're welcome. I appreciate your courtesy, and it's far in excess of the value of the code. I'll sure remember this one.
    ×

    Success!

    Help @smokyweb 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.19,
    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: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

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