Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help me fix my coding

    what am i doing wrong my alert pop up is not popping up to calculate my scores please help

    Code:
    
    
    
          <HTML>
              <HEAD>   
              <TITLE>JavaScript Grade Calculator</TITLE>
     <SCRIPT LANGUAGE="javascript">
    
    

    
    		
    
    
     function do_addition()
  {
  var lab1, lab2, test1, test2, cp, final;
  lab1=document.form1.Lab1Score.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 "+ test2 + " so I got to the function")
    alert("The value of Class Participation is "+ cp+ " so I got to the function")
    alert("The value of Final Exam is "+ final + " so I got to the function")
    
    result=parseFloat(lab1)+parseFloat(lab2)+parseFloat(test1)+parseFloat(test2)+parseFloat(cp)+parseFloat(final);
    
    document.form1.Total.value=result;
    
    
     if (result >=405 && result<=450) {alert("Total Points of "+result+" gives you an A")}  
     if (result >=360 && result<=404) {alert("Total Points of "+result+" gives you an B")}  
     if (result >=292 && result<=359) {alert("Total Points of "+result+" gives you an C")}  
     if (result >=247 && result<=291) {alert("Total Points of "+result+" gives you an D")}  
     if (result >=0 && result<=246) {alert("Total Points of "+result+" gives you an F")}  
           
    
           }
    
    
    
    
              	
    </SCRIPT>
    
    
              </HEAD> 
              <BODY>
    
    <center><form name="form1">
      
      
     Lab #1 (30 points):
      	    <input type="text" name="Lab1Score" size="5"><br>
     Lab #2 (70 points):
      	    <input type="text" name="Lab2Score" size="5"><br>
     Test #1 (100 points):
      	    <input type="text" name="Test1Score" size="5"><br>
     Test #2 (100 points):
      	    <input type="text" name="Test2Score" size="5"><br>
     Class Participation (50 points):
      	    <input type="text" name="CPScore" size="5"><br>
     Final Exam(100 points):
      	    <input type="text" name="FinalScore" size="5"><br>
    
    	
    
        <input type="button" value="Calculate your score" name="add" onClick="do_addition()"><br>
    
      <p>
      Total Points (450):    
      <input type="text" name="Total" size="6"><br>
      <input type=reset value=Reset><br>
    
    
    </center>
    
    	  </form> 
    
    
              </BODY>
    
    </html>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,732
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    When I copy your code I find additional ? characters in places. I think you have been using a word processor rather than a text editor to compose your code.

    Assigning a name to a form is obsolete. Use an id instead.

    It is your responsibility to die() if necessary….. - PHP Manual

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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