473,383 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How do you write a formula and use variables in javascript/html?

2
What I am looking to do is create a group of variables that work off each other and I'm not sure how to do this. I'm looking to create a webpage that compounds interest quarterly and am not sure how I would go about implementing the code and variables.


I believe I have the page lain out but am not sure how to go about making the variables change with each quarter. So I can get quarter one complete, but have no idea how to write the formulas or code that work off the first quarter to complete the second quarter. Here is my haphazard attempt and what I have done so far. Any help is greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1. <!doctype html>
  2. <!-- attempt3.html                                  some guy -->
  3. <!-- Web page that calculates the calculates interest quarterly -->
  4. <!-- =================================================== -->
  5.  
  6. <html>
  7.  <head>
  8.    <title> quarterly interest </title>
  9.  </head>
  10.  
  11.  <body>
  12.    <h2>Quarterly Interest Calculator</h2>
  13.    <p>
  14.  
  15. <table border="1">
  16. <tr>
  17.      <th>Beginning Balance:</th> <th>$<input type="text" id="amountBox" size=10 value="10000"></th>
  18.      <br>
  19. </tr>
  20. <tr>
  21.      <th>Interest Rate:</th> <th><input type="text" id="interestBox" size=10 value="3.5">%</th>
  22.    </p>  
  23.    <input type="button" value="Click for Calculation" 
  24.           onclick="Q1 = parseFloat(document.getElementById('amountBox').value);
  25.                    interest = Q1 * ((document.getElementById('interestBox').value)/100);
  26.                    document.getElementById('outputDiv').innerHTML=    
  27.             'Total interest Earned: ' + interest;">
  28. <script>
  29.  document.getElementById('outputDiv')
  30.       <br>
  31. <table border="1">
  32.  
  33. <tr>
  34. <th>Quarter</th>
  35. <th>Principal</th>
  36. <th>Interest Earned</th>
  37. </tr>
  38.  
  39. <tr>
  40. <td>1</td>
  41. <td>$</td>
  42. <td>$ </td>
  43. </tr>
  44.  
  45. <tr>
  46. <td>2</td>
  47. <td>$</td>
  48. <td>$</td>
  49. </tr>
  50.  
  51. <tr>
  52. <td>3</td>
  53. <td>$</td>
  54. <td>$</td>
  55. </tr>
  56.  
  57. <tr>
  58. <td>4</td>
  59. <td>$</td>
  60. <td>$</td>
  61. </tr>
  62.  
  63. </table> 
  64.  
  65.    <hr>
  66.    <div id="outputDiv"></div>
  67.  
  68.  </body>
  69.  
  70. </html>
  71.  
Sep 26 '11 #1
1 2984
Nk Inc
2
I'm starting to get a bit closer to what I need to have but still feel lost. I will post my progress. I am still lost as to what I need to do with the variables to make this work. ANY help would be greatly appreciated at this point. I will continue to edit this as I go.
Expand|Select|Wrap|Line Numbers
  1. <!doctype html>
  2. <!-- attempt3.html                                  some guy -->
  3. <!-- Web page that calculates interest quarterly -->
  4. <!-- =================================================== -->
  5.  
  6. <html>
  7.  <head>
  8.  
  9.    <title> quarterly interest </title>
  10.  
  11.  </head>
  12.  
  13.  <body>
  14.  
  15.    <h2>Quarterly Interest Calculator</h2>
  16.  
  17.    <p>
  18.  
  19. <table border="1">
  20. <tr>
  21.      <th>Beginning Balance:</th> <th>$<input type="text" id="amountBox" size=10 value="10000"></th>
  22.  
  23.      <br>
  24. </tr>
  25. <tr>
  26.      <th>Interest Rate:</th> <th><input type="text" id="interestBox" size=10 value="3.5">%</th>
  27.  
  28.    </p>  
  29.  
  30.  
  31.    <input type="button" value="Click for Calculation" 
  32.  
  33.           onclick="Q1=document.getElementById('amountBox').value;
  34.  
  35.         interest=document.getElementById('interestBox').value)/100;
  36.  
  37.  
  38.  
  39.       <br>
  40.  
  41.  
  42. <table border="1">
  43.  
  44. <tr>
  45.  
  46. <th>Quarter</th>
  47.  
  48. <th>Principal</th>
  49.  
  50. <th>Interest Earned</th>
  51.  
  52. </tr>
  53.  
  54. <tr>
  55.  
  56. <td>1</td>
  57.  
  58. <td>$ 10,000 </td>
  59.  
  60. <td>$ 350 </td>
  61.  
  62. </tr>
  63.  
  64. <tr>
  65.  
  66. <td>2</td>
  67.  
  68. <td>$ 10,350</td>
  69.  
  70. <td>$ 362.25</td>
  71.  
  72. </tr>
  73.  
  74. <tr>
  75.  
  76. <td>3</td>
  77.  
  78. <td>$ 10712.25</td>
  79.  
  80. <td>$ 374.928</td>
  81.  
  82. </tr>
  83.  
  84. <tr>
  85.  
  86. <td>4</td>
  87.  
  88. <td>$ 11087.18</td>
  89.  
  90. <td>$ 388.05</td>
  91.  
  92. </tr>
  93.  
  94. </table> 
  95.  
  96.  
  97. <script type="text/javascript">
  98.  
  99.  
  100.         Q1=document.getElementById('amountBox').value;
  101.  
  102.         interest=document.getElementById('interestBox').value)/100;
  103.  
  104.         Qa=Q1*interest;
  105.  
  106.         Qb=Q2*interest;
  107.  
  108.         Qc=Q3*interest;
  109.  
  110.  
  111.  
  112.         Q2=Q1+Qa;
  113.  
  114.         Q3=Q2+Qb;
  115.  
  116.         Q4=Q3+Qc;"
  117. </script>
  118.  
  119.  
  120.  
  121.  
  122.    <hr>
  123.  
  124.  
  125.  
  126.  </body>
  127.  
  128. </html>
  129.  
Sep 26 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Phil Powell | last post by:
I am having a potential PHP/Javascript/HTML conflict going on in my code that I simply can't resolve - been wracking my brain for a good hour over this one and have come up with no good solution. ...
2
by: sneill | last post by:
MXLogic, a Denver, Colorado based software company with 100+ employees is looking for candidates with **VERY STRONG** AJAX, Javascript, HTML, and CSS skills. Our company is building...
1
by: Paradox | last post by:
Hi everyone, kinda new to Javascript. Here is the issue, I have a form that sends to a different action based on the button pushed. But it also is sending variables to the server as well. Here...
1
by: gkellymail | last post by:
I have a small javascript/html code below that demonstrates that problem I'm having in a larger program. I've tried all kinds of things to get it to work, but it just won't do what I want. I've...
2
by: justplain.kzn | last post by:
Hi, I have a table with dynamic html that contains drop down select lists and readonly text boxes. Dynamic calculations are done on change of a value in one of the drop down select lists. ...
15
by: fanchun | last post by:
I already built 2 javacript files factor.js and parm.js. factor.js is an array, having several factor as elements. for example, factor.js looks like: var factor= parm.js is also an array, having...
6
by: jim | last post by:
I am seeking a .Net component that handles CSS, Javascript, HTML and PHP editing, validation and auto-completion (intellisense would be great). I have searched Google and componentsource but have...
0
by: alan cravey | last post by:
I have been successful with passing variables from html to a flash movie by using flashVars; however, I need these variables to be passed to multiple flash (swf) movies. In particular, they need to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.