SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    May 2008
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Computing average [was: pls pls pls help me...]

    i need help on a calculator script, one that can do averaging, here's the setup:

    in a form there are 3 cells

    in the first cell: ill input the value
    also in the first cell whatever i input it should add up to the current value it has.

    2nd cell is where i input the divisor

    in the 3nd cell: the average

    thank you so much for your help.
    this would mean alot to me..

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,260
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)

    calculator form script

    Hi 2ji8888, welcome to the forums,
    What do you have for the form's mark-up and javascript so far?

  3. #3
    SitePoint Member
    Join Date
    May 2008
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you for the reply,

    i know this may sound absurd but i havent got any yet, im still waiting for a good samaritan to create the script for me, once i have it then ill create my page, reason is that ill base my design on it.

    thanks.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    That's putting the cart before the horse, but here goes.

    Code javascript:
    var amount = document.getElementById('value');
    var divisor = document.getElementById('divisor');
    var average = document.getElementById('average');
     
    value.total = value.total || 0;
    value.count = value.values || 0;
     
    var value = amount / divisor;
    amount.total += value;
    amount.count += 1;
     
    amount.value = amount.total;
    average.value = amount.total / amount.count;
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Member
    Join Date
    May 2008
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's putting the cart before the horse, but here goes.
    right... lol. thank you kind sir. ill try this one...

    also. this is really stupid but how will i call this script inside my page? can u provide the script aswell? im a beginner, sorry. thanx.

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Code html4strict:
    <script src="path/to/averaging.js"></script>

    Some people put a type attribute on the script tag, but when the script is coming in from an external file the server header for the file is used instead. This means that the type attribute is ignored, so there's no use to putting it in.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Member
    Join Date
    May 2008
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's what i did.. it aint working... im stupid with codes sorry.


    <html>
    <head><title>test</title>

    <script src="path/to/averaging.js">

    var amount = document.getElementById('value');
    var divisor = document.getElementById('divisor');
    var average = document.getElementById('average');

    value.total = value.total || 0;
    value.count = value.values || 0;

    var value = amount / divisor;
    amount.total += value;
    amount.count += 1;

    amount.value = amount.total;
    average.value = amount.total / amount.count;

    </script>

    </head>
    <body>

    <div align='left' font-family: verdana; background-color : F2F2F2; font-size: 11px; border:1px solid

    black;><font face="Verdana" size="1" color="RED">Calls Handled : </font><input type='text' name='value'

    value='0' </div>


    <div align='left' font-family: verdana; background-color : F2F2F2; font-size: 11px; border:1px solid

    black;><font face="Verdana" size="1" color="RED">Calls Handled : </font><input type='text' name='divisor'

    value='0' </div>


    <div align='left' font-family: verdana; background-color : F2F2F2; font-size: 11px; border:1px solid

    black;><font face="Verdana" size="1" color="RED">Calls Handled : </font><input type='text' name='average'

    value='0' </div>

    </body>
    </html>

  8. #8
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,260
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)

    code and mark-up

    You are using a script tag for an external javascript file named averaging.js, but putting the code for that file inside the script tag.
    Also, the input tags should be inside a form tag.

    Are you getting any error messages? Sorry, but "doesn't work" isn't very helpful.
    It's a good habit to validate the HTML too. http://validator.w3.org/


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •