Javascript display value of function


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

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">
<td id="dsalary"><center>Your Salary</center>

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.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

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.
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.
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);
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

I would add the showsalary() tot he end of calculateTotal()
In your HTML:

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.

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.
Dan560Author Commented:
nap0leon did not see your comment. will try your suggestions now
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.
Dan560Author Commented:
Perfect it works exactly the way I want it.

Many thanks
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.
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

From novice to tech pro — start learning today.