Help...Please!

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Nov 2009
Posts: 6
Reputation: mcrawford3911 is an unknown quantity at this point 
Solved Threads: 0
mcrawford3911 mcrawford3911 is offline Offline
Newbie Poster

Help...Please!

 
0
  #1
Nov 5th, 2009
Below is my code, I have two problems.
1. I would like to remove the E with the box from the webscreen. Is there a way to do this without messing up the calculations?
2. Would like question 2 and the answer to have a , . Example want 100,000 and not 100000.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function CalculateSum(form)
  5.  
  6. {
  7. Atext=form.input_A.value;
  8. Btext=form.input_B.value;
  9. Ctext=form.input_C.value;
  10. Dtext=form.input_D.value;
  11. Etext=form.input_E.value;
  12. var A = parseFloat(Atext);
  13. var B = parseFloat(Btext);
  14. var C = parseFloat(Ctext);
  15. var D = parseFloat(Dtext);
  16. var E =parseFloat(Etext);
  17. if(E<300)
  18. form.Answer_for_E.value="Jugs";
  19. else
  20. if((E>=300) && (E<800))
  21. form.Answer_for_E.value="Drums";
  22. else
  23. if((E>=800) && (E<6601))
  24. form.Answer_for_E.value="IBC";
  25. else
  26. form.Answer_for_E.value="Bulk";
  27. form.Answer.value = (A * B / C * D);
  28.  
  29. }
  30. </script>
  31. </head>
  32. <body>
  33. <form name="Calculator" method="post">
  34.  
  35. <p>Enter the number of SCR trucks you operate: <input type=text name="input_A" size=10></p>
  36.  
  37. <p>Enter the average miles for a single truck, traveled in one year (default is 100,000 miles p.a.): <input type='text' name="input_B" size='10' value='100000'></p>
  38.  
  39. <p>Enter the average fuel mileage of your trucks (measured as MPG, defaults is 6 MPG): <input type='text' name="input_C" size='10' value='6'></p>
  40.  
  41. <P style="margin-top: 0; margin-bottom: 0">Default dosage rate is 2% DEF per every gallon of diesel fuel based on engine manufactures: <input type='text' name="input_D" size='10' value=.02></p>
  42. <p style="margin-top: 0; margin-bottom: 0">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  43. (Please enter percent as a decimal. ie 2% is entered as .02) </p>
  44. <p>E<INPUT TYPE=TEXT NAME="input_E" SIZE=10>
  45. <P><INPUT TYPE="button" VALUE="Average yearly gallons of DEF you may consume:" name="AddButton" onClick="CalculateSum(this.form)">
  46. <input name='Answer' type=text value"gallons comsumed" size="20">
  47. <p>Recommended form of package to be used when ordering DEF:
  48. <input name='Answer_for_E' type=text value"here will be the answer for E" size="20">
  49.  
  50. <P><INPUT TYPE="reset" VALUE="Clear Fields" name="ClearButton"></P>
  51.  
  52.  
  53.  
  54. </FORM>
  55.  
  56.  
  57.  
  58. </BODY>
  59.  
  60. </HTML>
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 885
Reputation: Airshow will become famous soon enough Airshow will become famous soon enough 
Solved Threads: 127
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark
 
0
  #2
Nov 5th, 2009
Mcrawford3911,

HTML supports hidden fields, which are invisible to the user but are addressable by javascript and get submitted with the rest of the form.
  1. <input type="hidden" name="input_e" size="10" />
This function returns a string version of a number with commas added to the left of a decimal point (if present). You can pass to it an integer or float or string representations of integer or float. It is tolerant of alhabetic characters accidentally passed.
  1. function addcommas( val ){
  2. var parts = (''+val).split('.');//Make sure value is a string and split at decimal point (if present) into array.
  3. var pattern = new RegExp('(-?[0-9]+)([0-9]{3})');
  4. while(pattern.test(parts[0])) { parts[0] = parts[0].replace(pattern, '$1,$2'); }//Add thousands separators only to the part found left of decimal point, or whole string if no dp present.
  5. return parts.join('.');//Put decimal parts back together and return.
  6. }
This is a modified version of something I found here, with credit to joshie76.

Airshow
Last edited by Airshow; Nov 5th, 2009 at 8:21 pm.
50% of the solution lies in accurately describing the problem!
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 6
Reputation: mcrawford3911 is an unknown quantity at this point 
Solved Threads: 0
mcrawford3911 mcrawford3911 is offline Offline
Newbie Poster

Thank you!

 
0
  #3
Nov 6th, 2009
I have it all figured out now...thank you!
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the JavaScript / DHTML / AJAX Forum


Views: 413 | Replies: 2
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC