www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 11-04-2009, 07:46 PM
    mcrawford mcrawford is offline
    Registered User
     
    Join Date: Nov 2009
    Posts: 1
    Help...been working on this all day!

    I’m using javascript, below is the form. If you go to form.Answer.value = (A * B / C * D) 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?

    <!-- 2005/11/08 Science Buddies: JavaScript calculator, adds two numbers -->
    <HTML>
    <HEAD>
    <TITLE>Simple Adder</TITLE>

    <!-- saved from url=(0030)http://www.sciencebuddies.org/ -->
    <!-- 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>
    Reply With Quote
      #2  
    Old 11-04-2009, 11:10 PM
    JMRKER JMRKER is offline
    Registered User
     
    Join Date: Dec 2005
    Location: FL
    Posts: 4,262
    Exclamation

    Typo:
    Code:
    var D = parseFloat(Ctext);
    Probably should be:
    Code:
    var D = parseFloat(Dtext);
    And .2 is not 2%, it is 20%
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 07:27 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.