| | |
Help...Please!
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2009
Posts: 6
Reputation:
Solved Threads: 0
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.
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)
<html> <head> <script type="text/javascript"> function CalculateSum(form) { Atext=form.input_A.value; Btext=form.input_B.value; Ctext=form.input_C.value; Dtext=form.input_D.value; Etext=form.input_E.value; var A = parseFloat(Atext); var B = parseFloat(Btext); var C = parseFloat(Ctext); var D = parseFloat(Dtext); var E =parseFloat(Etext); if(E<300) form.Answer_for_E.value="Jugs"; else if((E>=300) && (E<800)) form.Answer_for_E.value="Drums"; else if((E>=800) && (E<6601)) form.Answer_for_E.value="IBC"; else form.Answer_for_E.value="Bulk"; form.Answer.value = (A * B / C * D); } </script> </head> <body> <form name="Calculator" method="post"> <p>Enter the number of SCR trucks you operate: <input type=text name="input_A" size=10></p> <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> <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> <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> <p style="margin-top: 0; margin-bottom: 0"> (Please enter percent as a decimal. ie 2% is entered as .02) </p> <p>E<INPUT TYPE=TEXT NAME="input_E" SIZE=10> <P><INPUT TYPE="button" VALUE="Average yearly gallons of DEF you may consume:" name="AddButton" onClick="CalculateSum(this.form)"> <input name='Answer' type=text value"gallons comsumed" size="20"> <p>Recommended form of package to be used when ordering DEF: <input name='Answer_for_E' type=text value"here will be the answer for E" size="20"> <P><INPUT TYPE="reset" VALUE="Clear Fields" name="ClearButton"></P> </FORM> </BODY> </HTML>
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.
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.
This is a modified version of something I found here, with credit to joshie76.
Airshow
HTML supports hidden fields, which are invisible to the user but are addressable by javascript and get submitted with the rest of the form.
HTML Syntax (Toggle Plain Text)
<input type="hidden" name="input_e" size="10" />
javascript Syntax (Toggle Plain Text)
function addcommas( val ){ var parts = (''+val).split('.');//Make sure value is a string and split at decimal point (if present) into array. var pattern = new RegExp('(-?[0-9]+)([0-9]{3})'); 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. return parts.join('.');//Put decimal parts back together and return. }
Airshow
Last edited by Airshow; Nov 5th, 2009 at 8:21 pm.
50% of the solution lies in accurately describing the problem!
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Javascript read text file and create table
- Next Thread: opacity in javascript
Views: 412 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxexample ajaxjspservlets array autoplay blackjack browser captcha captchaformproblem cart child class close codes date debugger dependent developer disablefirebug dom editor element embed engine enter events explorer ext file firefox flash form forms frameworks game gears getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe java javascript javascripthelp2020 jquery jsf jsp jump libcurl maps margin marquee masterpage math media menu object onerror onmouseoutdivproblem onreadystatechange parent passing paypal pdf php player position post programming prototype rated redirect safari scale scriptlets scroll search security size software solutions sources star stars stretch synchronous toggle tweet unicode variables web webkit webservice window \n





