Results 1 to 8 of 8
  1.    #1  
    Basically what we have to do is enter our values into the text fields and have them add up into one. This is what I have done so far, I am just learning how to do this so I am kind of stuck. When I run it I click the button to add it doesn't add anything

    <HTML>
    <HEAD>
    <title> Grade Calculator </title>
    <script language="JavaScript">

    function do_addition()
    {
    var lab1, lab2, test1, test2, final, cp;
    lab1=document.form1.Lab1Score.value;
    lab2=document.form2.Lab2Score.value;
    test1=document.form3.Test1Score.value;
    test2=document.form4.Test2Score.value;
    final=document.form5.FinalExamScore.value;
    cp=document.form6.ClassParticipationScore.value;



    alert("The value of Lab 1 is "+lab1+" so I got to the function")
    alert("The value of Lab 2 is "+lab2+" so I got to the function")
    alert("The value of Test 1 is "+test1+" so I got to the function")
    alert("The value of Test 2 is "+test1+" so I got to the function")
    alert("The value of Final Exam is "+final+" so I got to the function")
    alert("The value of Class Participation is "+cp+" so I got to the function")





    }
    </SCRIPT>
    </HEAD>
    <BODY>



    <body bgcolor="grey">
    <FONT size="3" color="black" FACE="Verdana">
    <H1><b>Calculate Grades</b></h1>


    <form name="form1">
    Lab#1 (30 points):
    <input type="text" name="Lab1Score"size="5"><br>

    <form name="form2">
    Lab#2 (70 points):
    <input type="text" name="Lab2Score"size="5"><br>

    <form name="form3">
    Test#1 (100 points):
    <input type="text" name="Test1Score"size="5"><br>

    <form name="form4">
    Test#2 (100 points):
    <input type="text" name="Test2Score"size="5"><br>

    <form name="form5">
    Final Exam (100 points):
    <input type="text" name="FinalExamScore"size="5"><br>

    <form name="form6">
    Class Participation (50 points):
    <input type="text" name="ClassParticipationScore"size="5"><br>

    <input type="button" style="color: red" value="Calculate your score" name="add" onClick="do_addition()"><br>

    <form name="form7">
    Total Points (450 points):
    <input type="output" name="TotalPointsScore"size="5">








    </form>
    </body>
    </html
    Prē *********♥
    1Ghz
    Pixi *********♥
    Patched up
    (Gone)
    Now on a Samsung Epic
    *Creator of the best thread on precentral*

    RIP

  2. nhavar's Avatar
    Posts
    285 Posts
    Global Posts
    293 Global Posts
    #2  
    Is having multiple forms a requirement of the test. If not just use one form, like so:
    <form name="form1">
    Lab#1 (30 points):
    <input type="text" name="Lab1Score"size="5" />
    Lab#2 (70 points):
    <input type="text" name="Lab2Score"size="5" />
    Test#1 (100 points):
    <input type="text" name="Test1Score"size="5" />
    Test#2 (100 points):
    <input type="text" name="Test2Score"size="5" />
    Final Exam (100 points):
    <input type="text" name="FinalExamScore"size="5" />
    Class Participation (50 points):
    <input type="text" name="ClassParticipationScore"size="5" />
    <input type="button" style="color: red" value="Calculate your score" name="add" onClick="do_addition()" />

    Total Points (450 points):
    <input type="output" name="TotalPointsScore"size="5" />
    </form>


    The problem you are having is because you are not adding the fields up to create the total. You are getting all the values, but you don't have a step here that adds the values up, or assigns them back into the TotalPointsScore field.
  3. #3  
    I also would just use a single <form>, and then use the following to add up the numbers:

    Code:
    function do_addition()
    {
    
    var lab1, lab2, test1, test2, final, cp, total;
    
    lab1=parseInt(document.form1.Lab1Score.value);
    lab2=parseInt(document.form1.Lab2Score.value);
    test1=parseInt(document.form1.Test1Score.value);
    test2=parseInt(document.form1.Test2Score.value);
    final=parseInt(document.form1.FinalExamScore.value);
    cp=parseInt(document.form1.ClassParticipationScore.value);
    
    total = lab1 + lab2 + test1 + test2 + final + cp;
    
    document.form1.TotalPointsScore.value = total;
    }
    cohoman

    Palm Apps:

    jVault and jChecklist
  4. nhavar's Avatar
    Posts
    285 Posts
    Global Posts
    293 Global Posts
    #4  
    Quote Originally Posted by cohoman View Post
    I also would just use a single <form>, and then use the following to add up the numbers:

    Code:
    function do_addition()
    {
    
    var lab1, lab2, test1, test2, final, cp, total;
    
    lab1=parseInt(document.form1.Lab1Score.value);
    lab2=parseInt(document.form1.Lab2Score.value);
    test1=parseInt(document.form1.Test1Score.value);
    test2=parseInt(document.form1.Test2Score.value);
    final=parseInt(document.form1.FinalExamScore.value);
    cp=parseInt(document.form1.ClassParticipationScore.value);
    
    total = lab1 + lab2 + test1 + test2 + final + cp;
    
    document.form1.TotalPointsScore.value = total;
    }
    Oh man! You're not supposed to give him the answer, just nudge him in the right direction!
  5.    #5  
    Thanks guys for the help I really appreciate it, the multiple forms were from my trial and error process, just trying stuff to see if it made a difference. I knew I was missing something but I am a noob at this stuff. I kept rereading my teachers lecture notes for a solution but could not find it. I did learn from this though so thanks!
    Prē *********♥
    1Ghz
    Pixi *********♥
    Patched up
    (Gone)
    Now on a Samsung Epic
    *Creator of the best thread on precentral*

    RIP

  6. nhavar's Avatar
    Posts
    285 Posts
    Global Posts
    293 Global Posts
    #6  
    Quote Originally Posted by glamisfanatic View Post
    Thanks guys for the help I really appreciate it, the multiple forms were from my trial and error process, just trying stuff to see if it made a difference. I knew I was missing something but I am a noob at this stuff. I kept rereading my teachers lecture notes for a solution but could not find it. I did learn from this though so thanks!
    Some other tips
    1. Be consistent in how you write elements <H1></h1> should be <h1></h1>
    2. Use well formed lowercase tags - an element should always have an end <input type="text" /> or <br /> <h1></h1> <form></form>
    3. Use the latest stable standard e.g. XHTML (HTML 5 isn't ready yet)
    4. Use CSS and do away with font, b, i, u. They're deprecated in the newer standards anyway.
    5. Use labels with your inputs.
    6. Pick a doctype - picking the right one cuts down on the hacks you need to be cross browser compliant.
    7. Cache your JavaScript object references
    example instead of:
    var el1 = document.form1.element1.value;
    var el2 = document.form1.element2.value;
    var el3 = document.form1.element3.value;
    use
    var myForm = document.form1;
    var el1 = myForm.element1.value;
    var el2 = myForm.element2.value;
    var el3 = myForm.element3.value;

    It reduces traversal of the nodeset - speeding things up a little, makes for less typing and is a quicker read.
  7.    #7  
    Quote Originally Posted by nhavar View Post
    Some other tips
    1. Be consistent in how you write elements <H1></h1> should be <h1></h1>
    2. Use well formed lowercase tags - an element should always have an end <input type="text" /> or <br /> <h1></h1> <form></form>
    3. Use the latest stable standard e.g. XHTML (HTML 5 isn't ready yet)
    4. Use CSS and do away with font, b, i, u. They're deprecated in the newer standards anyway.
    5. Use labels with your inputs.
    6. Pick a doctype - picking the right one cuts down on the hacks you need to be cross browser compliant.
    7. Cache your JavaScript object references
    example instead of:
    var el1 = document.form1.element1.value;
    var el2 = document.form1.element2.value;
    var el3 = document.form1.element3.value;
    use
    var myForm = document.form1;
    var el1 = myForm.element1.value;
    var el2 = myForm.element2.value;
    var el3 = myForm.element3.value;

    It reduces traversal of the nodeset - speeding things up a little, makes for less typing and is a quicker read.

    Cool! Thanks a lot man
    Prē *********♥
    1Ghz
    Pixi *********♥
    Patched up
    (Gone)
    Now on a Samsung Epic
    *Creator of the best thread on precentral*

    RIP

  8. #8  
    Also whether you are using a single form or multiple, you need to close the form tag at the end of each one. Not totally sure if this would affect the JavaScript execution, but it sure will mess up your HTML output..

Posting Permissions