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
    Apr 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Display Subject Result

    Hi Everyone,
    I'm working on a website, where user add subjects result, (such as French = 80, English = 70, etc..) when user click on button, it has to display at the next text-field the Letter grade (such as if user adds 90, the letter grade will display A.).
    My problem is as follow:
    When user adds all the subjects result, and clicked on display letter result button, displays the letter grade of the first subject on all the other text-field, regardless of whether the outcome of the other subjects are different. Could you tell me what is wrong on my codes, please?
    Thank you.
    HTML
    Code:
    <form id="form">
          <h3> Subjects Calculation</h3>
    
    <tr>
            <td>French</td>
    	    <td><input type = "text"  id = "sub" /></td>
    		<td><input type = "text" size = "3" id = "result1" readonly="readonly"/></td>
         </tr>
    	 
         <tr>
            <td>English</td>
    	    <td><input type = "text"  id = "sub" /></td>
    		<td><input type = "text" size = "3"  id = "result2" readonly="readonly" /></td>
    	 </tr>
    	 
    	 <tr>
            <td>German</td>
    	    <td><input type = "text"  id = "sub" /></td>
    		<td><input type = "text" size = "3" id = "result3" readonly="readonly" /></td>
         </tr>
    	 
    	 <tr>
           <td>Dutch</td>
    	   <td><input type = "text"  id = "sub" /></td>
    	   <td><input type = "text" size = "3" id = "result4" readonly="readonly" /></td>
         </tr>
    	 
    <!-- Button for precomputation of the total result --> 
    	 <tr>
    	     <p>
    	        <input type = "button" onclick = "gpa();"  id="submit"  value = "Display Letter Grade" />
    			<input type="reset" value="Reset"/>
    	     </p>
    	</tr>
    	
        </form>
    Javascript
    Code:
    function gpa() 
    {
       var subject = document.getElementById("sub").value;
       
    
     
    if (subject >= 90)
    {
        document.getElementById("result1").value = "A";
    	document.getElementById("result2").value = "A";
    	document.getElementById("result3").value = "A";
    	document.getElementById("result4").value = "A";
    	
    }
    
    if (subject <= 89 && subject  >= 85)
    {
        document.getElementById("result1").value = "B";
    	document.getElementById("result2").value = "B";
    	document.getElementById("result3").value = "B";
    	document.getElementById("result4").value = "B";
    	
    }
    
    if (subject  <= 84 && subject >= 70)
    {
        document.getElementById("result1").value = "C";
    	document.getElementById("result2").value = "C";
    	document.getElementById("result3").value = "C";
    	document.getElementById("result4").value = "C";
    	
    }
    
    if (subject  <= 69 && subject  >= 55)
    {
       document.getElementById("result1").value = "D";
       document.getElementById("result2").value = "D";
       document.getElementById("result3").value = "D";
       document.getElementById("result4").value = "D";
       
    }
    
    if (subject <= 54 && subject  >= 40)
    {
       document.getElementById("result1").value = "E";
       document.getElementById("result2").value = "E";
       document.getElementById("result3").value = "E";
       document.getElementById("result4").value = "E";
       
    }
    
    if (subject  < 40)
    {
       document.getElementById("result1").value = "F";
       document.getElementById("result2").value = "F";
       document.getElementById("result3").value = "F";
       document.getElementById("result4").value = "F";   
    }
    
    }

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Your HTML is invalid. You are only allowed to use each id once in a web page - the values for id must be unique within the page.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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