[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Javascript display value of function

Posted on 2012-03-12
10
Medium Priority
?
258 Views
Last Modified: 2012-03-12
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
0
Comment
Question by:Dan560
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
10 Comments
 
LVL 18

Expert Comment

by:nap0leon
ID: 37709851
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
 
LVL 2

Author Comment

by:Dan560
ID: 37709875
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
 
LVL 5

Expert Comment

by:rkeith2412
ID: 37709902
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 5

Expert Comment

by:rkeith2412
ID: 37709914
I would add the showsalary() tot he end of calculateTotal()
0
 
LVL 18

Accepted Solution

by:
nap0leon earned 2000 total points
ID: 37710068
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
 
LVL 2

Author Comment

by:Dan560
ID: 37710199
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
 
LVL 2

Author Comment

by:Dan560
ID: 37710274
nap0leon did not see your comment. will try your suggestions now
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 37710283
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
 
LVL 2

Author Comment

by:Dan560
ID: 37710314
Perfect it works exactly the way I want it.

Many thanks
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 37710319
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

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question