| | |
Please help!!! JavaScript!
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
i’m using javascript, below is the form. If you go to the(A * B / C * D); part of the form. For some reason it does not work…do not know if I have something wrong. But if I were to enter 30 as A, 100,000 as B, 6 as C, and .2 as D. The answer should be 10,000. Can you help me figure out what is wrong?
html Syntax (Toggle Plain Text)
<!-- 2005/11/08 Science Buddies: JavaScript calculator, adds two numbers --> <HTML> <HEAD> <TITLE>Simple Adder</TITLE> <!-- saved from url=(0030)[url]http://www.sciencebuddies.org/[/url] --> <!-- When this code is saved as a local file, the preceding line tells Internet Explorer to treat this file according to the security rules for the Internet zone (plus any security rules specific for the Science Buddies website). --> <SCRIPT LANGUAGE="JavaScript"> <!-- old browsers can't handle JavaScript functions so comment them out // This is a single-line JavaScript comment. // Below is a multi-line JavaScript comment. /* CalculateSum: this function has 3 arguments: Atext, Btext and form. It converts Atext and Btext to numbers using the built-in JavaScript "parseFloat" method. It then uses the form argument to output the sum of the numbers to the form's Answer field. Notice that the function does *not* need to know the the names of the form's input fields. Those values are passed as arguments. It does need to know that the form has a field named "Answer" so that it can put the result there. Here is how to end a multi-line JavaScript comment: */ function CalculateSum(Atext, Btext, Ctext, Dtext, form) { var A = parseFloat(Atext); var B = parseFloat(Btext); var C = parseFloat(Ctext); var D = parseFloat(Ctext); form.Answer.value = (A * B / C * D); } /* ClearForm: this function has 1 argument: form. It clears the input and answer fields on the form. It needs to know the names of the INPUT elements in order to do this. */ function ClearForm(form) { form.input_A.value = ""; form.input_B.value = ""; form.input_C.value = ""; form.input_D.value = ""; form.Answer.value = ""; } // end of JavaScript functions --> </SCRIPT> </HEAD> <BODY> <P><FONT SIZE="+2">Simple Adder</FONT></P> <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></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></P> <P>Default dosage rate is 2% DEF per every gallon of diesel fuel based on engine manufactures: <INPUT TYPE=TEXT NAME="input_D" SIZE=10></P> <P><INPUT TYPE="button" VALUE="Average yearly gallons of DEF you may consume" name="AddButton" onClick="CalculateSum(this.form.input_A.value, this.form.input_B.value, this.form.input_C.value, this.form.input_D.value, this.form)"></P> <P><INPUT TYPE="button" VALUE="Clear Fields" name="ClearButton" onClick="ClearForm(this.form)"></P> <P>Answer = <INPUT TYPE=TEXT NAME="Answer" SIZE=12></P> </FORM> </BODY> </HTML> </html>
Last edited by Ezzaral; 24 Days Ago at 11:59 am. Reason: Added [code] [/code] tags. Please use them to format any code that you post.
0
#2 24 Days Ago
html tags should really be lower case, values quoted, corrected
html Syntax (Toggle Plain Text)
<html> <head> <title>Simpler Adder</title> <script type='text/javascript'> // corrected <!-- function CalculateSum(Atext, Btext, Ctext, Dtext, form) { var A = parseFloat(Atext); var B = parseFloat(Btext); var C = parseFloat(Ctext); var D = parseFloat(Dtext); // Error Ctext declared form.Answer.value = (A * B / C * D); } function ClearForm(form) { form.input_A.value = ""; form.input_B.value = ""; form.input_C.value = ""; form.input_D.value = ""; form.Answer.value = ""; } --></script></head> <body> <p><font size="+2">Simple Adder</font></p> <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: <input type='text' name="input_B" size='10' value='100000'></p> <p>Enter the average fuel mileage of your trucks (measured as MPG): <input type='text' name="input_C" size='10' value='6'></p> <p>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><input type="button" value="Average yearly gallons of DEF you may consume" name="AddButton" onClick="CalculateSum(this.form.input_A.value, this.form.input_B.value, this.form.input_C.value, this.form.input_D.value, this.form)"></p> <p><input type='button' value="Clear Fields" name="ClearButton" onClick="ClearForm(this.form)"></p> <p>Answer = <input type='text' name="Answer" size='12' readonly></p> </form> </body> </html>
Last edited by almostbob; 24 Days Ago at 12:53 am.
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
•
•
Join Date: Nov 2009
Posts: 6
Reputation:
Solved Threads: 0
Thank you, I'm going to look at the code and figure out the difference....I really appreciate it!!!
•
•
•
•
html tags should really be lower case, values quoted, correctedhtml Syntax (Toggle Plain Text)
<html> <head> <title>Simpler Adder</title> <script type='text/javascript'> // corrected <!-- function CalculateSum(Atext, Btext, Ctext, Dtext, form) { var A = parseFloat(Atext); var B = parseFloat(Btext); var C = parseFloat(Ctext); var D = parseFloat(Dtext); // Error Ctext declared form.Answer.value = (A * B / C * D); } function ClearForm(form) { form.input_A.value = ""; form.input_B.value = ""; form.input_C.value = ""; form.input_D.value = ""; form.Answer.value = ""; } --></script></head> <body> <p><font size="+2">Simple Adder</font></p> <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: <input type='text' name="input_B" size='10' value='100000'></p> <p>Enter the average fuel mileage of your trucks (measured as MPG): <input type='text' name="input_C" size='10' value='6'></p> <p>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><input type="button" value="Average yearly gallons of DEF you may consume" name="AddButton" onClick="CalculateSum(this.form.input_A.value, this.form.input_B.value, this.form.input_C.value, this.form.input_D.value, this.form)"></p> <p><input type='button' value="Clear Fields" name="ClearButton" onClick="ClearForm(this.form)"></p> <p>Answer = <input type='text' name="Answer" size='12' readonly></p> </form> </body> </html>
•
•
Join Date: Oct 2009
Posts: 17
Reputation:
Solved Threads: 2
0
#4 24 Days Ago
Last edited by futingkiller; 24 Days Ago at 11:55 am.
•
•
Join Date: Nov 2009
Posts: 6
Reputation:
Solved Threads: 0
Yes, I'm a huge copy and paster.
Do you know how to add a if statement to this???? I'm just learning and would love some advice.
Need a if statement as follows for the “Recommended form of package to be used when ordering DEF” ad button. E would be the answer from what you just helped with...but do not know how to add E either. Wish there was some kind of tutorial...I love to learn and when I get it myself it is even better. =IF(E<300,Jugs,IF(AND(E>=300,E<800),Drums,IF(AND(E>=800,E<6601),IBC,Mini Bulk)))
Do you know how to add a if statement to this???? I'm just learning and would love some advice.
Need a if statement as follows for the “Recommended form of package to be used when ordering DEF” ad button. E would be the answer from what you just helped with...but do not know how to add E either. Wish there was some kind of tutorial...I love to learn and when I get it myself it is even better. =IF(E<300,Jugs,IF(AND(E>=300,E<800),Drums,IF(AND(E>=800,E<6601),IBC,Mini Bulk)))
•
•
Join Date: Oct 2009
Posts: 17
Reputation:
Solved Threads: 2
-1
#6 24 Days Ago
html Syntax (Toggle Plain Text)
<html> <head> <title>Simpler Adder</title> <script type='text/javascript'> // corrected <!-- function CalculateSum(Atext, Btext, Ctext, Dtext, Etext, form) { var A = parseFloat(Atext); var B = parseFloat(Btext); var C = parseFloat(Ctext); var D = parseFloat(Dtext); // Error Ctext declared var E=parseFloat(Etext); if( E==300) form.Answer.value="E is equal to 300"; if(E > =300) form.Answer.value="E is greater than 300"; if(E <=300) form.Answer.value="E is smaller than 300"; if( E==0) form.Answer.value = (A * B / C * D); } function ClearForm(form) { form.input_A.value = ""; form.input_B.value = ""; form.input_C.value = ""; form.input_D.value = ""; form.Answer.value = ""; } --></script></head> <body> <p><font size="+2">Simple Adder</font></p> <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: <input type='text' name="input_B" size='10' value='100000'></p> <p>Enter the average fuel mileage of your trucks (measured as MPG): <input type='text' name="input_C" size='10' value='6'></p> <p>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>What that E stands for:<input type=text name="input_E" size=10 value="default value for E"></p> <p><input type="button" value="Average yearly gallons of DEF you may consume" name="AddButton" onClick="CalculateSum(this.form.input_A.value, this.form.input_B.value, this.form.input_C.value, this.form.input_D.value, this.form.input_E.value, this.form)"></p> <p><input type='reset' value="Clear Fields" name="ClearButton"></p> <p>Answer = <input type='text' name="Answer" size='12' readonly></p> </form> </body> </html>
Last edited by peter_budo; 24 Days Ago at 7:13 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
![]() |
Similar Threads
- Make any Javascript fit any new size (JavaScript / DHTML / AJAX)
- News Story: Anonymous griefers induce epileptic seizures using JavaScript (HTML and CSS)
- HTML, CSS, JavaScript Developer (Web Development Job Offers)
- JavaScript / AJAX Guru (Software Development Job Offers)
- Are you a PHP and Javascript junkie? It's time you met Emma. (Software Development Job Offers)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: scrollTo(x.y)
- Next Thread: Redirect to page??
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp animate array automatically beta box bug calendar cart checkbox class codes column cookies createrange() css cursor date debugger decimal design dom download dropdown editor element embed enter error explorer firefox focus frameworks getselection google gwt hint html htmlform ie7 iframe images index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jsp jump listbox maps masterpage math menu microsoft mimic mp4 object onmouseover parent paypal php player position post problem programming progressbar prototype redirect regex runtime safari scale scriptlets search select session shopping size sql text textarea toggle variables w3c website window windowofwords windowsxp wysiwyg \n








