Javascript display value of function

Hi,

I have followed a guide online that performs a real time calculation using javascript

http://www.javascript-coder.com/javascript-form/javascript-calculator-script.phtml

I have modified the formto so that it calculates an employees potential bonus for the year. This works ok however I want to show a break down of  the values used below.. i.e getsalary()

I used the following javascript

function showsalary()
{
    
    var salary = getsalary();
    var salary2 = document.getElementById('dsalary');
    salary2.innerHTML = salary;
}

Open in new window


and the following html -
<center><table border="1" WIDTH="330" class="header1">
<tr>
<td id="dsalary"><center>Your Salary</center>
</tr>
</td>
</table></center>
<br>
<br>

Open in new window


This should display the salary that has been entered in the form. However it just remains blank.

Can someone please help? I have attached the javascript and html used for your reference.
formcalculations.js
style.css
cakeform.html
LVL 2
Dan560Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nap0leonCommented:
I don't see anywhere where you are calling the function "showsalary()".

BTW, your HTML has several errors which may be causing it to not work right:
the closing </td> in your "Your Salary" table should go before the </tr>.

Missing a closing > (two locations):
in salary: <input type="text"  name="salary" id="salary"
in aprrating: </select


Also, you have an extra </select in CSR (missing a >, but since the whole thing is extra, it should be rmeoved.
0
Dan560Author Commented:
Ok I used the following code in javascript

 var salary2 = document.getElementById('dsalary');

I then used code in my html

<td id="dsalary"><center>Your Salary</center>

however I am open to any help as I am by no means an expert have really self taught myself with the help of Google.

Apologies for the poor coding.
0
rkeith2412Commented:
There are two issues.

1.  You never tell your page to run the show salary function.

2.  In your function getsalary() howmany = parseInt(salary.value); should be howmany = parseInt(quantity.value);
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

rkeith2412Commented:
I would add the showsalary() tot he end of calculateTotal()
0
nap0leonCommented:
In your HTML:
onload=hideTotal()

Open in new window

Tries to hide a piece of HTML that does not exist ('totalPrice').  I removed it.

In your JS file:
howmany = parseInt(salary.value);

Open in new window

salary is not defined, so you cannot get the value of it.
looks like a couple lines above needs to be changed to say 'salary' instead of 'quantity'
    var salary = theForm.elements["salary"];

Open in new window


There may have been a few other small edits I made along the way... I think there were two "body" tags too.
cakeform.html
formcalculations.js
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dan560Author Commented:
but my function calculatetotal() is working I just want to show the getsalary() value on another part of the page without changing anything to the calculatetotal() function.
0
Dan560Author Commented:
nap0leon did not see your comment. will try your suggestions now
0
nap0leonCommented:
Using the pages I posted, please test them out and then detail what changes you would like to make.

Right now, when you select any of the drop-downs, the total pay including bonus displays in as "YOUR ANNUAL BONUS COULD BE: €101250" and the salary (the same number that was entered in the salary input at the top of the page) displays in the "YOUR SALARY" area.

I would presume you actually want bonus amount, and not 'total compensation' displayed for "Your annual bonus could be..." and where you have salary showing at the bottom of the page is where you actually want total compensation, but that's just a guess.
0
Dan560Author Commented:
Perfect it works exactly the way I want it.

Many thanks
0
nap0leonCommented:
Love it when posts stream in at the same time. ;o)
Let us know if you need any help adjusting which values appear in each section.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.