Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dividing two figures

Status
Not open for further replies.

arabia

Technical User
Nov 4, 2002
8
GB
I am making a website about the Apollo missions. In total, the apollo missions cost £12,450,887,792.68. I want a user to be able to enter their salary in one box, click on a button, and for a piece of script to return how many years it would take for them to save that amount of money based on their salary. Obviously, we're just talking about 12450887792.68 / salary = years, but I've never used Javascript b4, and so I'm not sure how to do it.

Thanks for any help you can offer.

David.
 
here is a way you can do it :

<form name=&quot;myForm&quot;>
<input type=&quot;text&quot; name=&quot;salary&quot;>
<input type=&quot;button&quot; onclick=&quot;alert('It would have taken you ' + (12450887792.68 / document.myForm.salary.value) + ' years to save up for this mission.')&quot;>
</form> Gary Haran
 
Thank you for your kind assistance.

David.
 
This works great, thanks. Is there any way to have a form where there is an output onscreen rather than it coming up as an alert box?
 
Use an empty <INPUT TYPE=&quot;text&quot; ID=&quot;txtOut&quot;>, and in the onClick use:

onClick=&quot;document.getElementByID('txtOut').value='It would...

That should do the trick! Cheers,
Nico
 
As it's an output, I would also make the text box read only,
Code:
<INPUT TYPE=&quot;text&quot; ID=&quot;txtOut&quot; readonly>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top