473,382 Members | 1,720 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,382 software developers and data experts.

Calculate text fields and display the results in a different text field

I will have three text fields; all numbers.
1st A
2nd 4*B
3rd C

I need to divide the above by 6.

The results show display in a separate results text field
Mar 5 '13 #1
10 2046
Rabbit
12,516 Expert Mod 8TB
Please show us the code you're using. Also, you will need to explain your question in more detail because I'm not sure what you're trying to do.
Mar 5 '13 #2
I need this for both HTML/JAVASCRIPT and Android Java
Expand|Select|Wrap|Line Numbers
  1. function estimate(Opt,ML,Pess, Res)
  2. {
  3. var four = 4;
  4. var denominator = 6;
  5. var ML = ML*4;
  6. var numerator = Opt + ML + Pess;
  7. var n1 = 0;
  8. var n2 = 0;
  9. var n3 = 0;
  10. return Res = numerator / denominator;
  11. if (document.getElementById('Opt').value != "")
  12. n1 = parseInt(document.getElementById('Opt').value);
  13. if (document.getElementById('ML').value != "")
  14. n2 = parseInt(document.getElementById('ML').value);
  15. if (document.getElementById('Pess').value != "")
  16. n3 = parseInt(document.getElementById('Pess').value);
  17.  
  18.  
  19. }
  20.  
  21.  
  22. function calc() {
  23. var Res = document.getElementById('Res');
  24. Res.value = estimate(document.getElementById('Res').value);
  25.  
  26. </script>
  27.  
  28. </head>
  29. <body>
  30. <p style="text-align: center; font-size: xx-large; font-style: normal; font-variant: small-caps; font-weight: bold; color: #2D7176;">Pert Calculator</p>
  31. <div style="position: relative; width: 955px; left: 285px; top: 0.08px; height: 87.28px;">
  32. <label style="font-size: xx-large; font-style: oblique; text-align: center; width: 1010px; position: relative; left: 0px; top: 0px;">This PERT application will help you estimate PERT. The formula for PERT is ((Optimistic + (4 * Most Likely) + Pessimistic) / by 6)</label>
  33. </div>
  34.  
  35.  
  36. <div>
  37. <label style="position: relative; left: 85.00px; top: 70.93px; font-size: x-large; color: #937B62;">Optimistic</label>
  38. <label style="position: relative; left: 105.00px; top: 71.93px; font-size: large;">Most preferred</label>
  39. <input id="Opt" type="text" style="position: relative; width: 276px; height: 28px; left: 401.16px; top: 79.08px;">
  40. </div>
  41.  
  42. <div>
  43. <label style="position: relative; left: 85.00px; top: 120.93px; font-size: x-large; color: #937B62;">Most Likely</label>
  44. <label style="position: relative; left: 105.00px; top: 121.93px; font-size: large;">More than likely the case</label>
  45. <input id="ML" type="text" style="position: relative; width: 276px; height: 28px; left: 308.88px; top: 124.08px;">
  46. </div>
  47.  
  48. <div>
  49. <label style="position: relative; left: 85.00px; top: 170.93px; font-size: x-large; color: #937B62;">Pessimistic</label>
  50. <label style="position: relative; left: 105.00px; top: 171.93px; font-size: large;">Worst Case</label>
  51. <input id="Pess" type="text" style="position: absolute; width: 276px; height: 28px; left: 640px; top: 451px;">
  52. </div>
  53.  
  54. <div>
  55. <label style="position: relative; left: 85.00px; top: 226.93px; font-size: x-large; color: #937B62;">Result</label>
  56. <input id="Res" type="text" style="position: relative; width: 276px; height: 28px; left: 570.67px; top: 226.35px;" readonly="" >
  57. </div>
  58.  
  59. <div style="height: 80.44px;">
  60. <button value="Calculate" onclick="calc()" style="position: relative; width: 165px; height: 54.27px; left: 80px; top: 273.08px; font-size: x-large;" type="button">Calculate</button>
  61. </div>
  62.  
  63. <div style="height: 40px;">
  64. <button id="reset" type="reset" value="Reset" style="position: relative; width: 125px; height: 45px; left: 1010px; top: 243.08px; font-size: x-large;">Reset</button>
  65. </div>
  66.  
  67. <div>
  68. <img src="/CBA%20Logo%20Pert%20Calculator.fw.png" style="position: relative; left: 4px; top: -411.92px;">
  69. </div>
  70.  
  71.  
  72.  
  73. </body>
  74. </html>
Mar 5 '13 #3
Rabbit
12,516 Expert Mod 8TB
Need what? You haven't explained clearly what it is you want. I find your first post confusing. And your post with the code seems to have little to no relation to your first.
Mar 5 '13 #4
I cannot get the result text field to populate correctly.
There are four text fields; all numbers.
The user would enter these numbers.
Text field 1: Opt
Text field 2: 4*ML (4 times X)
Text field 3: Pess

All three text fields are added together and once added, the total will be divided by 6.

Text field 4: Is the results of the first three fields
Mar 6 '13 #5
Rabbit
12,516 Expert Mod 8TB
For one thing, your javascript code can't even run. You didn't close your calc function. You also call your estimate function but only pass one parameter when it expects 4. And you return from the estimate function even though there's more code below it.
Mar 6 '13 #6
I have modified the code but the results are still not reflecting the result text field:
Expand|Select|Wrap|Line Numbers
  1. function estimate(Opt,ML,Pess, Res)
  2.         {
  3.             var Opt = parseInt(document.getElementById('Opt').value);
  4.             var ML = parseInt(document.getElementById('ML').value);
  5.             var Pess = parseInt(document.getElementById('Pess').value);
  6.  
  7.             var Res = ((Opt + (4 * ML) + Pess)/6);
  8.            document.getElementById("showsum").innerHTML = Res;}
  9. </script>
  10.  
  11. </head>
  12. <body>
  13.     <p style="text-align: center; font-size: xx-large; font-style: normal; font-variant: small-caps; font-weight: bold; color: #2D7176;">Pert Calculator</p>
  14.     <div style="position: relative; width: 955px; left: 285px; top: 0.08px; height: 87.28px;">
  15.         <label style="font-size: xx-large; font-style: oblique; text-align: center; width: 1010px; position: relative; left: 0px; top: 0px;">This PERT application will help you estimate PERT. The formula for PERT is ((Optimistic + (4 * Most Likely) + Pessimistic) / by 6)</label>
  16.     </div>
  17.  
  18.  
  19.     <div>
  20.         <label style="position: relative; left: 85.00px; top: 70.93px; font-size: x-large; color: #937B62;">Optimistic</label>
  21.         <label style="position: relative; left: 105.00px; top: 71.93px; font-size: large;">Most preferred</label>
  22.         <input id="Opt" type="text" style="position: relative; width: 276px; height: 28px; left: 401.16px; top: 79.08px;">
  23.     </div>
  24.  
  25.     <div>
  26.         <label style="position: relative; left: 85.00px; top: 120.93px; font-size: x-large; color: #937B62;">Most Likely</label>
  27.         <label style="position: relative; left: 105.00px; top: 121.93px; font-size: large;">More than likely the case</label>
  28.         <input id="ML" type="text" style="position: relative; width: 276px; height: 28px; left: 308.88px; top: 124.08px;">
  29.     </div>
  30.  
  31.     <div>
  32.         <label style="position: relative; left: 85.00px; top: 170.93px; font-size: x-large; color: #937B62;">Pessimistic</label>
  33.         <label style="position: relative; left: 105.00px; top: 171.93px; font-size: large;">Worst Case</label>
  34.         <input id="Pess" type="text" style="position: absolute; width: 276px; height: 28px; left: 640px; top: 451px;">
  35.     </div>
  36.  
  37.     <div>
  38.         <label style="position: relative; left: 85.00px; top: 226.93px; font-size: x-large; color: #937B62;">Result</label>
  39.         <input id="Res" type="text" style="position: relative; width: 276px; height: 28px; left: 570.67px; top: 226.35px;" readonly=""  >
  40.  
  41.     </div>
  42.  
  43.     <div style="height: 80.44px;">
  44.         <button value="Calculate"  onclick="estimate()" style="position: relative; width: 165px; height: 54.27px; left: 80px; top: 273.08px; font-size: x-large;" type="button">Calculate</button>
  45.  
  46.     </div>
  47.  
  48.     <div style="height: 40px;">
  49.         <button id="reset" type="reset" value="Reset" style="position: relative; width: 125px; height: 45px; left: 1010px; top: 243.08px; font-size: x-large;">Reset</button>
  50.     </div>
  51.  
  52. </body>
  53. </html>
  54.  
Mar 7 '13 #7
Rabbit
12,516 Expert Mod 8TB
Your estimate function is still expecting 4 parameters but now you're passing no parameters at all. You also have no element with an id of showsum.
Mar 7 '13 #8
Hi Rabbit, I think I have fixed that but the fields are not adding up together, they are just stacking on each other. So if I enter values: 14, 15, and 16, the result is 141516.
Please tell me how to add the fields and then divide
Expand|Select|Wrap|Line Numbers
  1.         function estimate(Opt, ML, Pess, Res)
  2.         {
  3.             var Opt = parseInt(document.getElementById('Opt').value);
  4.             var ML = parseInt(document.getElementById('ML').value * 4);
  5.             var Pess = parseInt(document.getElementById('Pess').value);
  6.             var Res = parseInt(document.getElementById('Res').value);
  7.  
  8.             document.getElementById('Res').value = (document.getElementById("Opt").value + document.getElementById('ML').value + document.getElementById('Pess').value / 6);
  9. </script>
  10.  
  11. </head>
  12. <body>
  13.     <p style="text-align: center; font-size: xx-large; font-style: normal; font-variant: small-caps; font-weight: bold; color: #2D7176;">Pert Calculator</p>
  14.     <div style="position: relative; width: 955px; left: 285px; top: 0.08px; height: 87.28px;">
  15.         <label style="font-size: xx-large; font-style: oblique; text-align: center; width: 1010px; position: relative; left: 0px; top: 0px;">This PERT application will help you estimate PERT. The formula for PERT is ((Optimistic + (4 * Most Likely) + Pessimistic) / by 6)</label>
  16.     </div>
  17.  
  18.  
  19.     <div>
  20.         <label style="position: relative; left: 85.00px; top: 70.93px; font-size: x-large; color: #937B62;">Optimistic</label>
  21.         <label style="position: relative; left: 105.00px; top: 71.93px; font-size: large;">Most preferred</label>
  22.         <input id="Opt" type="text" style="position: relative; width: 276px; height: 28px; left: 401.16px; top: 79.08px;">
  23.     </div>
  24.  
  25.     <div>
  26.         <label style="position: relative; left: 85.00px; top: 120.93px; font-size: x-large; color: #937B62;">Most Likely</label>
  27.         <label style="position: relative; left: 105.00px; top: 121.93px; font-size: large;">More than likely the case</label>
  28.         <input id="ML" type="text" style="position: relative; width: 276px; height: 28px; left: 308.88px; top: 124.08px;">
  29.     </div>
  30.  
  31.     <div>
  32.         <label style="position: relative; left: 85.00px; top: 170.93px; font-size: x-large; color: #937B62;">Pessimistic</label>
  33.         <label style="position: relative; left: 105.00px; top: 171.93px; font-size: large;">Worst Case</label>
  34.         <input id="Pess" type="text" style="position: absolute; width: 276px; height: 28px; left: 640px; top: 451px;">
  35.     </div>
  36.  
  37.     <div>
  38.         <label style="position: relative; left: 85.00px; top: 226.93px; font-size: x-large; color: #937B62;">Result</label>
  39.         <input id="Res" type="text" style="position: relative; width: 276px; height: 28px; left: 570.67px; top: 226.35px;" readonly=""  >
  40.         <object id="divide"></object>
  41.         <object id="add"></object>
  42.     </div>
  43.  
  44.     <div style="height: 80.44px;">
  45.         <button value="Calculate" onclick="estimate()" style="position: relative; width: 165px; height: 54.27px; left: 80px; top: 273.08px; font-size: x-large;" type="button">Calculate</button>
  46.  
  47.     </div>
  48.  
  49.     <div style="height: 40px;">
  50.         <button id="reset" type="reset" value="Reset" style="position: relative; width: 125px; height: 45px; left: 1010px; top: 243.08px; font-size: x-large;">Reset</button>
  51.     </div>
  52.  
  53. </body>
  54. </html>
  55.  
Mar 7 '13 #9
Rabbit
12,516 Expert Mod 8TB
You made changes that I didn't say to make. Go back and make only the those two changes I mentioned.
Mar 8 '13 #10
jmrker
17
Please read 'Rabbit's request...
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title> </title>
  4. <script type="text/javascript">
  5.     function estimate() {
  6.       var Opt = parseInt(document.getElementById('Opt').value);
  7.       var ML = parseInt(document.getElementById('ML').value);
  8.       var Pess = parseInt(document.getElementById('Pess').value);
  9.       var Res = ((Opt + (4 * ML) + Pess)/6);
  10.       document.getElementById("showsum").value= Res.toFixed(2);
  11.     }
  12.     </script>
  13.  
  14.     </head>
  15.     <body>
  16.       <form id="myForm" action="" method="post" onsubmit="return false">
  17.  
  18.         <p style="text-align: center; font-size: xx-large; font-style: normal; font-variant: small-caps; font-weight: bold; color: #2D7176;">Pert Calculator</p>
  19.         <div style="position: relative; width: 955px; left: 285px; top: 0.08px; height: 87.28px;">
  20.             <label style="font-size: xx-large; font-style: oblique; text-align: center; width: 1010px; position: relative; left: 0px; top: 0px;">
  21.              This PERT application will help you estimate PERT. The formula for PERT is ((Optimistic + (4 * Most Likely) + Pessimistic) / by 6)</label>
  22.         </div>
  23.  
  24.         <div>
  25.             <label style="position: relative; left: 85.00px; top: 70.93px; font-size: x-large; color: #937B62;">Optimistic</label>
  26.             <label style="position: relative; left: 105.00px; top: 71.93px; font-size: large;">Most preferred</label>
  27.             <input id="Opt" type="text" style="position: relative; width: 276px; height: 28px; left: 401.16px; top: 79.08px;">
  28.         </div>
  29.  
  30.         <div>
  31.             <label style="position: relative; left: 85.00px; top: 120.93px; font-size: x-large; color: #937B62;">Most Likely</label>
  32.             <label style="position: relative; left: 105.00px; top: 121.93px; font-size: large;">More than likely the case</label>
  33.             <input id="ML" type="text" style="position: relative; width: 276px; height: 28px; left: 308.88px; top: 124.08px;">
  34.         </div>
  35.  
  36.         <div>
  37.             <label style="position: relative; left: 85.00px; top: 170.93px; font-size: x-large; color: #937B62;">Pessimistic</label>
  38.             <label style="position: relative; left: 105.00px; top: 171.93px; font-size: large;">Worst Case</label>
  39.             <input id="Pess" type="text" style="position: absolute; width: 276px; height: 28px; left: 640px; top: 451px;">
  40.         </div>
  41.  
  42.         <div>
  43.             <label style="position: relative; left: 85.00px; top: 226.93px; font-size: x-large; color: #937B62;">Result</label>
  44.             <input id="showsum" type="text" style="position: relative; width: 276px; height: 28px; left: 570.67px; top: 226.35px;" readonly=""  >
  45.  
  46.         </div>
  47.  
  48.         <div style="height: 80.44px;">
  49.             <button value="Calculate"  onclick="estimate()"
  50.                style="position: relative; width: 165px; height: 54.27px; left: 80px; top: 273.08px; font-size: x-large;" type="button">
  51.             Calculate</button>
  52.  
  53.         </div>
  54.  
  55.         <div style="height: 40px;">
  56.             <button id="reset" type="reset" value="Reset"
  57.                style="position: relative; width: 125px; height: 45px; left: 1010px; top: 243.08px; font-size: x-large;">
  58.             Reset</button>
  59.         </div>
  60.       </form>    
  61.     </body>
  62.     </html>
  63.  
Note: You need a <form> tag for the 'Reset' to work.
Also, your 'showsum' is a .value, not a .innerHTML
Finally, no need to pass parameters in the 'estimate()' function.
Mar 9 '13 #11

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

Similar topics

4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
0
by: Sehboo | last post by:
Hi, I have a webpage with two text fields, and a button. Text fields are for Names and phonenumber. Once user clicks on the button, the form does some processing. Problem is that I have a...
3
by: Frustrated Developer via DotNetMonster.com | last post by:
I have posted a couple times on here already and found the user community to be very helpful. I took on a project before I realized how difficult a time I'm having working with a database....
0
by: Ennio-Sr | last post by:
Hi all! After a very long struggle I finally succeded in transferring my old *.dbf file and the relating *.dbt (alias memo fields) to a pg table. For the time being I put the memo field in a...
3
by: John Smith | last post by:
I have two text fields in a table. One is Height, one is width. Some examples of what might be each field: Height Width 35' 35' 8' 6' 4 to 6...
7
by: Tzanko | last post by:
As we all know, there is a 8060 bytes size limit on SQL Server rows. I have a table which requires a number of text fields (5 or 6). Each of these text fields should support a max of 4000...
2
by: letam | last post by:
Hello, Thank you in advance for any help, it will be most appreciated! I need to be able to disable several text fields, until the user enters a value in a certain text field. Once they enter a...
2
by: parnellsquare | last post by:
I am a software tester - the developers I am working with are telling me there is no way to allow users to enter text that includes punctuation marks like apostrophes, quate marks, semi-colons,...
0
by: Kassimu | last post by:
Hi guys out there, There is this database Iam creating, I have a table with 40 fields among which there are Date/time, Text, Number, Memo and Yes/No fields and I have created the form bound to that...
1
gcoaster
by: gcoaster | last post by:
Hello Group, I was wondering if anyone out there can help me I have a form Unbound List Box Control on the form The row source is a built-in query. I was wondering if there is anyway 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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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.