0

hello to everyone, I have this code as a Grading System, but whenever I press a key on my keyboard, it shows Not a Number or NaN! Please help! I need this by two days! Please! :(

<html>
<title>Grading System</title>
<head>
<script type="text/Javascript">
function totalM()
{
QM1 = parseInt(document.average.QM1.value);
QM2 = parseInt(document.average.QM2.value);
LQM = parseInt(document.average.LQM.value);
AM = parseInt(document.average.AM.value);
TM = parseInt(document.average.TM.value);
totalM = (QM1+QM2+LQM+AM);
document.average.TM.value = totalM;
}
function totalF()
{
QF1 = parseInt(document.average.QF1.value);
QF2 = parseInt(document.average.QF2.value);
LQF = parseInt(document.average.LQF.value);
AF = parseInt(document.average.AF.value);
TF = parseInt(document.average.TF.value);
totalF = (QF1+QF2+LQF+AF);
document.average.TF.value = totalF;
}
function averageGrade()
{
TF = parseInt(document.average.TF.value);
TM = parseInt(document.average.TM.value);
GPA = parseInt(document.average.GPA.value);
FG = parseInt(document.average.FG.value);
V = parseInt(document.average.V.value);
averageGrade = (TF+TM)/(2);
document.average.FG.value = averageGrade;
if (document.average.FG.value == 99)
   {
   document.average.GPA.value =  "The Highest is 95" ;
   document.average.V.value = "The Highest is 95";
   }
else if (document.average.FG.value >= 98 && document.average.FG.value < 99)
   {
   document.average.GPA.value =  "The Highest is 95" ;
   document.average.V.value = "The Highest is 95";
   }
else if (document.average.FG.value >= 97 && document.average.FG.value < 98)
   {
   document.average.GPA.value =  "The Highest is 95" ;
   document.average.V.value = "The Highest is 95";
   }
else if (document.average.FG.value >= 96 && document.average.FG.value < 97)
   {
   document.average.GPA.value =  "The Highest is 95" ;
   document.average.V.value = "The Highest is 95";
   }
else if (document.average.FG.value >= 95 && document.average.FG.value < 96)
   {
   document.average.GPA.value =  "1.00" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 93 && document.average.FG.value < 95)
   {
   document.average.GPA.value =  "1.25" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 90 && document.average.FG.value < 93)
   {
   document.average.GPA.value =  "1.50" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 89 && document.average.FG.value < 90)
   {
   document.average.GPA.value =  "1.75" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 85 && document.average.FG.value < 89)
   {
   document.average.GPA.value =  "2.00" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 83 && document.average.FG.value < 85)
   {
   document.average.GPA.value =  "2.25" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 80 && document.average.FG.value < 83)
   {
   document.average.GPA.value =  "2.50" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 78 && document.average.FG.value < 80)
   {
   document.average.GPA.value =  "2.75" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 75 && document.average.FG.value < 78)
   {
   document.average.GPA.value =  "3.00" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value < 75)
   {
   document.average.GPA.value =  "Between 3.00 and 5.00" ;
   document.average.V.value = "Failed";
   }
else if (isNaN(document.average.FG.value = "Not a number"))
   {
   document.average.GPA.value =  "Not a number" ;
   document.average.V.value = "Not a number";
   }
}
</script>
<style type="text/css">
.style1 {
	font-family: Castellar;
}
.style4 {
	font-size: medium;
}
.style5 {
	text-align: center;
}
</style>
</head>
<h1 class="style1" align="center" style="font-family: Castellar; font-size: xx-large; font-weight: bolder; font-style: normal; font-variant: normal; text-transform: capitalize; color: #FFFFFF; text-decoration: blink">Grading System</h1>
<form name="average" action="GS.html" method="get">
<center><h1 class="style1" align="center" style="font-family: Castellar; font-size: x-large; font-weight: bolder; font-style: normal; font-variant: normal; text-transform: capitalize; color: #FFFFFF;><table style="width: 24%; height: 179px" cellspacing="3" cellpadding="3" class="style4" border="5" bgcolor="#FFFFFF" frame="box">Midterms</h1>
	<table style="width: 19%; height: 179px" cellspacing="3" cellpadding="2" class="style4" bgcolor="#FFFFFF" border="5" frame="box">
	<tr>
		<td class="style1">Quiz no. 1:</td>
		<td class="style1">
		<input name="QM1" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Quiz no. 2:</td>
		<td class="style1">
		<input name="QM2" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Long Quiz:</td>
		<td class="style1">
		<input name="LQM" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Attendance:</td>
		<td class="style1">
		<input name="AM" type="text" size=2 maxlength=2 onKeyPress="return totalM()">
		</td>
	</tr>
	<tr>
		<td class="style1">Total Midterms:</td>
		<td class="style1">
		<input type="text" name="TM" size=2 maxlength=2>
		</td>
	</tr>
</table> 
<h1 class="style1" align="center" style="font-family: Castellar; font-size: x-large; font-weight: bolder; font-style: normal; font-variant: normal; text-transform: capitalize; color: #FFFFFF;><table style="width: 24%; height: 179px" cellspacing="3" cellpadding="3" class="style4" border="5" bgcolor="#FFFFFF" frame="box">Finals</h1>
	<table style="width: 19%; height: 179px" cellspacing="3" cellpadding="2" class="style4" bgcolor="#FFFFFF" border="5" frame="box">
	<tr>
		<td class="style1">Quiz no. 1:</td>
		<td><input name="QF1" type="text" size=2 maxlength=2></td>
	</tr>
	<tr>
		<td class="style1">Quiz no. 2:</td>
		<td class="style1">
		<input name="QF2" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Long Quiz:</td>
		<td class="style1">
		<input name="LQF" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Attendance:</td>
		<td class="style1">
		<input name="AF" type="text" size=2 maxlength=2 onKeyPress="return totalF()">
		</td>
	</tr>
	<tr>
		<td class="style1">Total Finals: &nbsp; &nbsp; &nbsp;</td>
		<td class="style1">
		<input type="text" name="TF" size=2 maxlength=2 onKeyPress="return averageGrade()";>
		</td>
	</tr>
</table> 
<br>
<table style="width: 23%; height: 70px" cellspacing="3" cellpadding="2" class="style4" bgcolor="#FFFFFF" border="5" frame="box">
<tr>
  <td class="style1">Final Grade:</td>
  <td class="style1"><input type=text disabled="disabled" name="FG" size=21></td>
</tr>  
<tr>
  <td class="style1">G.P.A.</td>
  <td class="style6"><input type=text disabled="disabled" name="GPA" size=21></td>
</tr>
<tr> 
  <td class="style1">Verdict:</td>
  <td class="style6"><input type=text disabled="disabled" name="V" size=21></td>
</tr> 
</table>
<h1 class="style1" align="center" style="font-family: Castellar; font-size: x-large; font-weight: bolder; font-style: normal; font-variant: normal; text-transform: capitalize; color: #FFFFFF;><table style="width: 24%; height: 179px" cellspacing="3" cellpadding="3" class="style4" border="5" bgcolor="#FFFFFF" frame="box">
</center>
</form>
</html>

Edited by peter_budo: Keep it Organized - For easy readability, always wrap programming code within posts in [code] (code blocks).

2
Contributors
9
Replies
10
Views
7 Years
Discussion Span
Last Post by bavs_02
0

Hi there,

Just at first glance, you're calling the function by using onKeyPress . This means that as soon as you press a key the function gets called; there simply isn't a number in the field (yet) at the moment the function is being called. Try changing onKeyPress into onKeyUp for starters, and see if that works.

Good luck with your assignment,

Traevel

0

But I need to reset the value of the textbox when its is erased . . . How can I do it? please Help! :(

0

I have developed the code, but it does not show the correct answer... And I also need to reset the value of the textbox whenever a number is erased... Please help! :( Here's the Code:

<html>
<body background="1.jpg">
<title>Grading System</title>
<head>
<script type="text/Javascript">
function totalM()
{
QM1 = parseInt(document.average.QM1.value);
QM2 = parseInt(document.average.QM2.value);
LQM = parseInt(document.average.LQM.value);
AM = parseInt(document.average.AM.value);
TM = parseInt(document.average.TM.value);
totalM = (QM1+QM2+LQM+AM)/(4);
document.average.TM.value = totalM;
}
function totalF()
{
QF1 = parseInt(document.average.QF1.value);
QF2 = parseInt(document.average.QF2.value);
LQF = parseInt(document.average.LQF.value);
AF = parseInt(document.average.AF.value);
TF = parseInt(document.average.TF.value);
totalF = (QF1+QF2+LQF+AF)/(4);
document.average.TF.value = totalF;
}
function averageGrade()
{
TF = parseInt(document.average.TF.value);
TM = parseInt(document.average.TM.value);
GPA = parseInt(document.average.GPA.value);
FG = parseInt(document.average.FG.value);
V = parseInt(document.average.V.value);
averageGrade = (TF+TM)/(2);
document.average.FG.value = averageGrade;
if (document.average.FG.value == 99)
   {
   document.average.GPA.value =  "The Highest is 95" ;
   document.average.V.value = "The Highest is 95";
   }
else if (document.average.FG.value >= 98 && document.average.FG.value < 99)
   {
   document.average.GPA.value =  "The Highest is 95" ;
   document.average.V.value = "The Highest is 95";
   }
else if (document.average.FG.value >= 97 && document.average.FG.value < 98)
   {
   document.average.GPA.value =  "The Highest is 95" ;
   document.average.V.value = "The Highest is 95";
   }
else if (document.average.FG.value >= 96 && document.average.FG.value < 97)
   {
   document.average.GPA.value =  "The Highest is 95" ;
   document.average.V.value = "The Highest is 95";
   }
else if (document.average.FG.value >= 95 && document.average.FG.value < 96)
   {
   document.average.GPA.value =  "1.00" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 93 && document.average.FG.value < 95)
   {
   document.average.GPA.value =  "1.25" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 90 && document.average.FG.value < 93)
   {
   document.average.GPA.value =  "1.50" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 89 && document.average.FG.value < 90)
   {
   document.average.GPA.value =  "1.75" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 85 && document.average.FG.value < 89)
   {
   document.average.GPA.value =  "2.00" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 83 && document.average.FG.value < 85)
   {
   document.average.GPA.value =  "2.25" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 80 && document.average.FG.value < 83)
   {
   document.average.GPA.value =  "2.50" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 78 && document.average.FG.value < 80)
   {
   document.average.GPA.value =  "2.75" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 75 && document.average.FG.value < 78)
   {
   document.average.GPA.value =  "3.00" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value < 75)
   {
   document.average.GPA.value =  "Between 3.00 and 5.00" ;
   document.average.V.value = "Failed";
   }
else if (isNaN(document.average.FG.value = "Not a number"))
   {
   document.average.GPA.value =  "Not a number" ;
   document.average.V.value = "Not a number";
   }
}
</script>
<style type="text/css">
.style1 {
	font-family: Castellar;
}
.style4 {
	font-size: medium;
}
.style5 {
	text-align: center;
}
</style>
</head>
<h1 class="style1" align="center" style="font-family: Castellar; font-size: xx-large; font-weight: bolder; font-style: normal; font-variant: normal; text-transform: capitalize; color: #FFFFFF; text-decoration: blink">Grading System</h1>
<form name="average" action="GS.html" method="get">
<center><h1 class="style1" align="center" style="font-family: Castellar; font-size: x-large; font-weight: bolder; font-style: normal; font-variant: normal; text-transform: capitalize; color: #FFFFFF;><table style="width: 24%; height: 179px" cellspacing="3" cellpadding="3" class="style4" border="5" bgcolor="#FFFFFF" frame="box">Midterms</h1>
	<table style="width: 19%; height: 179px" cellspacing="3" cellpadding="2" class="style4" bgcolor="#FFFFFF" border="5" frame="box">
	<tr>
		<td class="style1">Quiz no. 1:</td>
		<td class="style1">
		<input name="QM1" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Quiz no. 2:</td>
		<td class="style1">
		<input name="QM2" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Long Quiz:</td>
		<td class="style1">
		<input name="LQM" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Attendance:</td>
		<td class="style1">
		<input name="AM" type="text" size=2 maxlength=2 onKeyUp="totalM()">
		</td>
	</tr>
	<tr>
		<td class="style1">Total Midterms:</td>
		<td class="style1">
		<input type="text" name="TM" size=2 maxlength=2>
		</td>
	</tr>
</table> 
<h1 class="style1" align="center" style="font-family: Castellar; font-size: x-large; font-weight: bolder; font-style: normal; font-variant: normal; text-transform: capitalize; color: #FFFFFF;><table style="width: 24%; height: 179px" cellspacing="3" cellpadding="3" class="style4" border="5" bgcolor="#FFFFFF" frame="box">Finals</h1>
	<table style="width: 19%; height: 179px" cellspacing="3" cellpadding="2" class="style4" bgcolor="#FFFFFF" border="5" frame="box">
	<tr>
		<td class="style1">Quiz no. 1:</td>
		<td><input name="QF1" type="text" size=2 maxlength=2></td>
	</tr>
	<tr>
		<td class="style1">Quiz no. 2:</td>
		<td class="style1">
		<input name="QF2" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Long Quiz:</td>
		<td class="style1">
		<input name="LQF" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Attendance:</td>
		<td class="style1">
		<input name="AF" type="text" size=2 maxlength=2 onKeyUp="totalF()">
		</td>
	</tr>
	<tr>
		<td class="style1">Total Finals: &nbsp; &nbsp; &nbsp;</td>
		<td class="style1">
		<input type="text" name="TF" size=2 maxlength=2 onKeyUp="averageGrade()">
		</td>
	</tr>
</table> 
<br>
<table style="width: 23%; height: 70px" cellspacing="3" cellpadding="2" class="style4" bgcolor="#FFFFFF" border="5" frame="box">
<tr>
  <td class="style1">Final Grade:</td>
  <td class="style1"><input type=text disabled="disabled" name="FG" size=21></td>
</tr>  
<tr>
  <td class="style1">G.P.A.</td>
  <td class="style6"><input type=text disabled="disabled" name="GPA" size=21></td>
</tr>
<tr> 
  <td class="style1">Verdict:</td>
  <td class="style6"><input type=text disabled="disabled" name="V" size=21></td>
</tr> 
</table>
<h1 class="style1" align="center" style="font-family: Castellar; font-size: x-large; font-weight: bolder; font-style: normal; font-variant: normal; text-transform: capitalize; color: #FFFFFF;><table style="width: 24%; height: 179px" cellspacing="3" cellpadding="3" class="style4" border="5" bgcolor="#FFFFFF" frame="box"><a href="About.html">About</a></h1>
</center>
</form>
</html>

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

0

In that case you would need to find a way to check whether all values are actually inserted in the text boxes. For instance:

if (/*all inputs are filled*/){
  // calculate average
} else {
  // update the field values
}

On a side note... it would be a lot easier if you would place your code in code-tags. Now I'll just have to guess the line numbers :P

Change line 5 in: <script type="text/javascript">
Change all the onKeyUp="totalM()" in: onKeyUp="javascript:totalM()" But remember that any key could trigger that, including TAB, which in return would cause errors. A submit button would be the simplest solution, but in order to keep the field updating on key press it would be best to monitor this by using events, instead of this 'ugly' onKeyUp solution.

To clear a field you could simply assign an empty value to the field: document.average.TM.value = "";

To check whether a field is empty, again use something like if(document.average.TM.value=="")

Finally, a few minor changes/remarks...

There are no <body> tags
The <title> should be between <head> tags
On line 126: the <h1> is nested incorrectly and there is an incorrect <table>
Same on line 159.

Hope this helps a little,

Traevel

Edited by happygeek: fixed formatting

0

I have improved the code again... But I need the textbox to be reset whenever a value is deleted in the textbox and when I press Enter... It will calculate again without using a reset button... This is my last problem now... By the way... Thanks for helping!^_^

<html>
<body bgcolor="blue">
<head>
<title>Grading System</title>
<script type="text/Javascript">
function totalM()
{
QM1 = parseInt(document.average.QM1.value);
QM2 = parseInt(document.average.QM2.value);
LQM = parseInt(document.average.LQM.value);
AM = parseInt(document.average.AM.value);
TM = parseInt(document.average.TM.value);
totalM = (QM1+QM2+LQM+AM)/(4);
document.average.TM.value = totalM;
}
function totalF()
{
QF1 = parseInt(document.average.QF1.value);
QF2 = parseInt(document.average.QF2.value);
LQF = parseInt(document.average.LQF.value);
AF = parseInt(document.average.AF.value);
TF = parseInt(document.average.TF.value);
totalF = (QF1+QF2+LQF+AF)/(4);
document.average.TF.value = totalF;
}
function averageGrade()
{
TF = parseInt(document.average.TF.value);
TM = parseInt(document.average.TM.value);
GPA = parseInt(document.average.GPA.value);
FG = parseInt(document.average.FG.value);
V = parseInt(document.average.V.value);
averageGrade = (TF+TM)/(2);
document.average.FG.value = averageGrade;
if (document.average.FG.value == 99)
   {
   document.average.GPA.value =  "The Highest is 95" ;
   document.average.V.value = "The Highest is 95";
   }
else if (document.average.FG.value >= 98 && document.average.FG.value < 99)
   {
   document.average.GPA.value =  "The Highest is 95" ;
   document.average.V.value = "The Highest is 95";
   }
else if (document.average.FG.value >= 97 && document.average.FG.value < 98)
   {
   document.average.GPA.value =  "The Highest is 95" ;
   document.average.V.value = "The Highest is 95";
   }
else if (document.average.FG.value >= 96 && document.average.FG.value < 97)
   {
   document.average.GPA.value =  "The Highest is 95" ;
   document.average.V.value = "The Highest is 95";
   }
else if (document.average.FG.value >= 95 && document.average.FG.value < 96)
   {
   document.average.GPA.value =  "1.00" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 93 && document.average.FG.value < 95)
   {
   document.average.GPA.value =  "1.25" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 90 && document.average.FG.value < 93)
   {
   document.average.GPA.value =  "1.50" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 89 && document.average.FG.value < 90)
   {
   document.average.GPA.value =  "1.75" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 85 && document.average.FG.value < 89)
   {
   document.average.GPA.value =  "2.00" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 83 && document.average.FG.value < 85)
   {
   document.average.GPA.value =  "2.25" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 80 && document.average.FG.value < 83)
   {
   document.average.GPA.value =  "2.50" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 78 && document.average.FG.value < 80)
   {
   document.average.GPA.value =  "2.75" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 75 && document.average.FG.value < 78)
   {
   document.average.GPA.value =  "3.00" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value < 75)
   {
   document.average.GPA.value =  "Between 3.00 and 5.00" ;
   document.average.V.value = "Failed";
   }
else if (isNaN(document.average.FG.value = "Not a number"))
   {
   document.average.GPA.value = "Not a number" ;
   document.average.V.value = "Not a number";
   }
}
</script>
<style type="text/css">
.style1 {
	font-family: Castellar;
}
.style4 {
	font-size: medium;
}
.style5 {
	text-align: center;
}
</style>
</head>
<h1 class="style1" align="center" style="font-family: Castellar; font-size: xx-large; font-weight: bolder; font-style: normal; font-variant: normal; text-transform: capitalize; color: #FFFFFF; text-decoration: blink">Grading System</h1>
<form name="average" action="GS.html" method="get">
<center><h1 class="style1" align="center" style="font-family: Castellar; font-size: x-large; font-weight: bolder; font-style: normal; font-variant: normal; text-transform: capitalize; color: #FFFFFF;><table style="width: 24%; height: 179px" cellspacing="3" cellpadding="3" class="style4" border="5" bgcolor="#FFFFFF" frame="box">Midterms</h1>
	<table style="width: 19%; height: 179px" cellspacing="3" cellpadding="2" class="style4" bgcolor="#FFFFFF" border="5" frame="box">
	<tr>
		<td class="style1">Quiz no. 1:</td>
		<td class="style1">
		<input name="QM1" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Quiz no. 2:</td>
		<td class="style1">
		<input name="QM2" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Long Quiz:</td>
		<td class="style1">
		<input name="LQM" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Attendance:</td>
		<td class="style1">
		<input name="AM" type="text" size=2 maxlength=2 onkeypress="{if (event.keyCode==13)totalM()}">
		</td>
	</tr>
	<tr>
		<td class="style1">Total Midterms:</td>
		<td class="style1">
		<input type="text" name="TM" size=2 maxlength=2>
		</td>
	</tr>
</table> 
<h1 class="style1" align="center" style="font-family: Castellar; font-size: x-large; font-weight: bolder; font-style: normal; font-variant: normal; text-transform: capitalize; color: #FFFFFF;><table style="width: 24%; height: 179px" cellspacing="3" cellpadding="3" class="style4" border="5" bgcolor="#FFFFFF" frame="box">Finals</h1>
	<table style="width: 19%; height: 179px" cellspacing="3" cellpadding="2" class="style4" bgcolor="#FFFFFF" border="5" frame="box">
	<tr>
		<td class="style1">Quiz no. 1:</td>
		<td><input name="QF1" type="text" size=2 maxlength=2></td>
	</tr>
	<tr>
		<td class="style1">Quiz no. 2:</td>
		<td class="style1">
		<input name="QF2" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Long Quiz:</td>
		<td class="style1">
		<input name="LQF" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Attendance:</td>
		<td class="style1">
		<input name="AF" type="text" size=2 maxlength=2 onkeypress="{if (event.keyCode==13)totalF()}">
		</td>
	</tr>
	<tr>
		<td class="style1">Total Finals: &nbsp; &nbsp; &nbsp;</td>
		<td class="style1">
		<input type="text" name="TF" size=2 maxlength=2 onkeypress="{if (event.keyCode==13)averageGrade()}">
		</td>
	</tr>
</table> 
<br>
<table style="width: 23%; height: 70px" cellspacing="3" cellpadding="2" class="style4" bgcolor="#FFFFFF" border="5" frame="box">
<tr>
  <td class="style1">Final Grade:</td>
  <td class="style1"><input type=text disabled="disabled" name="FG" size=21></td>
</tr>  
<tr>
  <td class="style1">G.P.A.</td>
  <td class="style6"><input type=text disabled="disabled" name="GPA" size=21></td>
</tr>
<tr> 
  <td class="style1">Verdict:</td>
  <td class="style6"><input type=text disabled="disabled" name="V" size=21></td>
</tr> 
</table>
<h1 class="style1" align="center" style="font-family: Castellar; font-size: x-large; font-weight: bolder; font-style: normal; font-variant: normal; text-transform: capitalize; color: #FFFFFF;><table style="width: 24%; height: 179px" cellspacing="3" cellpadding="3" class="style4" border="5" bgcolor="#FFFFFF" frame="box"><a href="About.html">About</a></h1>
</center>
</form>
</html>

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks).

0

Code tags :)

About the general code...

Errors: 12
Warnings: 140

<html>
<head>
  <title></title>
</head>
<body>
  <!--content here -->
</body>
</html>

About the JavaScript...

Like I said, build a condition to check for complete input-fields. It may require to rewrite most of the code and different triggering; you ask for an output change whenever someone deletes a number, but yet the only way to get an output in your current form is when someone fills out the numbers (top to bottom) and presses "enter" halfway down the field (which no one would've figured out unless he/she is browsing through your code).

A few last tips to simplify the code:

  • store document.average.FG.value in a variable
  • same with document.average.GPA.value
  • and document.average.V.value
  • about the conditional, for instance: if (QM1 != "" & QM2 != "" & ... ) etc.

Good luck,

Traevel

0

Thanks for correcting my errors... Its really helpful... But I need to reset the value of the textbox whenever the user deletes a number in the textbox... And when he hits enter again... It will calculate a new grade... Please be more specific! :( huhuhu! :( I feel so helpless! :( Please help! :(

0

I'll give you something to start with...

  • remove all the onkeypress/up/down="if()" etc.
  • if you have a function called totalM() do not name a variable totalM ...it just messes things up
  • check for a NaN to see whether all inputs are filled (just like you did on line 120)
  • complete the code below for your other calculations (this only covers the first table/form)
document.onkeydown = calc;
function calc(e){
	if (!e) var e = window.event;
	(e.keyCode) ? key = e.keyCode : key = e.which;
	if (key == 13){
		totalM();
		//totalF();
		//averageGrade();
	} else {
		document.average.TM.value = "";
	}
}

function totalM(){
	QM1 = parseInt(document.average.QM1.value);
	QM2 = parseInt(document.average.QM2.value);
	LQM = parseInt(document.average.LQM.value);
	AM = parseInt(document.average.AM.value);
	var total = ((QM1+QM2+LQM+AM)/(4));
	if(!isNaN(total)){
		document.average.TM.value = total;
	} else {
		document.average.TM.value = "";
	}
}

Good luck,

Traevel

0

wow! you're a genius man! THANK YOU SO MUCH! I GOT 100 ON MY FINALS AT LABORATORY IN COSC22! THANK YOU VERY MUCH! by the way here's the whole, improved and developed code of the Grading System just in case someone will need it again^_^:

<html>
<body bgcolor="blue">
<head>
<title>Grading System</title>
<script type="text/Javascript">
document.onkeydown = calc;
function calc(e){
	if (!e) var e = window.event;
	(e.keyCode) ? key = e.keyCode : key = e.which;
	if (key == 13){
		totalM();
		//totalF();
		//averageGrade();
	}
}

function totalM(){
	QM1 = parseInt(document.average.QM1.value);
	QM2 = parseInt(document.average.QM2.value);
	LQM = parseInt(document.average.LQM.value);
	AM = parseInt(document.average.AM.value);
	var total = ((QM1+QM2+LQM+AM)/(4));
	if(!isNaN(total)){
		document.average.TM.value = total;
	} else {
		document.average.TM.value = "";
	}
}

function totalF(){
	QF1 = parseInt(document.average.QF1.value);
	QF2 = parseInt(document.average.QF2.value);
	LQF = parseInt(document.average.LQF.value);
	AF = parseInt(document.average.AF.value);
	var total = ((QF1+QF2+LQF+AF)/(4));
	if(!isNaN(total)){
		document.average.TF.value = total;
	} else {
		document.average.TF.value = "";
	}
}

function averageGrade()
{
TF = parseInt(document.average.TF.value);
TM = parseInt(document.average.TM.value);
GPA = parseInt(document.average.GPA.value);
FG = parseInt(document.average.FG.value);
V = parseInt(document.average.V.value);
total = (TF+TM)/(2);
	if(!isNaN(total))
	document.average.FG.value = total;
if (document.average.FG.value == 99)
   {
   document.average.GPA.value =  "The Highest is 95" ;
   document.average.V.value = "The Highest is 95";
   }
else if (document.average.FG.value >= 98 && document.average.FG.value < 99)
   {
   document.average.GPA.value =  "The Highest is 95" ;
   document.average.V.value = "The Highest is 95";
   }
else if (document.average.FG.value >= 97 && document.average.FG.value < 98)
   {
   document.average.GPA.value =  "The Highest is 95" ;
   document.average.V.value = "The Highest is 95";
   }
else if (document.average.FG.value >= 96 && document.average.FG.value < 97)
   {
   document.average.GPA.value =  "The Highest is 95" ;
   document.average.V.value = "The Highest is 95";
   }
else if (document.average.FG.value >= 95 && document.average.FG.value < 96)
   {
   document.average.GPA.value =  "1.00" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 93 && document.average.FG.value < 95)
   {
   document.average.GPA.value =  "1.25" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 90 && document.average.FG.value < 93)
   {
   document.average.GPA.value =  "1.50" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 89 && document.average.FG.value < 90)
   {
   document.average.GPA.value =  "1.75" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 85 && document.average.FG.value < 89)
   {
   document.average.GPA.value =  "2.00" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 83 && document.average.FG.value < 85)
   {
   document.average.GPA.value =  "2.25" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 80 && document.average.FG.value < 83)
   {
   document.average.GPA.value =  "2.50" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 78 && document.average.FG.value < 80)
   {
   document.average.GPA.value =  "2.75" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value >= 75 && document.average.FG.value < 78)
   {
   document.average.GPA.value =  "3.00" ;
   document.average.V.value = "Passed";
   }
else if (document.average.FG.value < 75)
   {
   document.average.GPA.value =  "Between 3.00 and 5.00" ;
   document.average.V.value = "Failed";
   }
else if (isNaN(document.average.FG.value = "Not a number"))
   {
   document.average.GPA.value = "Not a number" ;
   document.average.V.value = "Not a number";
   }
}
</script>
<style type="text/css">
.style1 {
	font-family: Castellar;
}
.style4 {
	font-size: medium;
}
.style5 {
	text-align: center;
}
</style>
</head>
<h1 class="style1" align="center" style="font-family: Castellar; font-size: xx-large; font-weight: bolder; font-style: normal; font-variant: normal; text-transform: capitalize; color: #FFFFFF; text-decoration: blink">Grading System</h1>
<form name="average" action="GS.html" method="get">
<center><h1 class="style1" align="center" style="font-family: Castellar; font-size: x-large; font-weight: bolder; font-style: normal; font-variant: normal; text-transform: capitalize; color: #FFFFFF;><table style="width: 24%; height: 179px" cellspacing="3" cellpadding="3" class="style4" border="5" bgcolor="#FFFFFF" frame="box">Midterms</h1>
	<table style="width: 19%; height: 179px" cellspacing="3" cellpadding="2" class="style4" bgcolor="#FFFFFF" border="5" frame="box">
	<tr>
		<td class="style1">Quiz no. 1:</td>
		<td class="style1">
		<input name="QM1" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Quiz no. 2:</td>
		<td class="style1">
		<input name="QM2" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Long Quiz:</td>
		<td class="style1">
		<input name="LQM" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Attendance:</td>
		<td class="style1">
		<input name="AM" type="text" size=2 maxlength=2 onkeypress="{if (event.keyCode==13)totalM()}">
		</td>
	</tr>
	<tr>
		<td class="style1">Total Midterms:</td>
		<td class="style1">
		<input type="text" name="TM" size=2 maxlength=2>
		</td>
	</tr>
</table> 
<h1 class="style1" align="center" style="font-family: Castellar; font-size: x-large; font-weight: bolder; font-style: normal; font-variant: normal; text-transform: capitalize; color: #FFFFFF;><table style="width: 24%; height: 179px" cellspacing="3" cellpadding="3" class="style4" border="5" bgcolor="#FFFFFF" frame="box">Finals</h1>
	<table style="width: 19%; height: 179px" cellspacing="3" cellpadding="2" class="style4" bgcolor="#FFFFFF" border="5" frame="box">
	<tr>
		<td class="style1">Quiz no. 1:</td>
		<td><input name="QF1" type="text" size=2 maxlength=2></td>
	</tr>
	<tr>
		<td class="style1">Quiz no. 2:</td>
		<td class="style1">
		<input name="QF2" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Long Quiz:</td>
		<td class="style1">
		<input name="LQF" type="text" size=2 maxlength=2>
		</td>
	</tr>
	<tr>
		<td class="style1">Attendance:</td>
		<td class="style1">
		<input name="AF" type="text" size=2 maxlength=2 onkeypress="{if (event.keyCode==13)totalF()}">
		</td>
	</tr>
	<tr>
		<td class="style1">Total Finals: &nbsp; &nbsp; &nbsp;</td>
		<td class="style1">
		<input type="text" name="TF" size=2 maxlength=2 onkeypress="{if (event.keyCode==13)averageGrade()}">
		</td>
	</tr>
</table> 
<br>
<table style="width: 23%; height: 70px" cellspacing="3" cellpadding="2" class="style4" bgcolor="#FFFFFF" border="5" frame="box">
<tr>
  <td class="style1">Final Grade:</td>
  <td class="style1"><input type=text disabled="disabled" name="FG" size=21></td>
</tr>  
<tr>
  <td class="style1">G.P.A.</td>
  <td class="style6"><input type=text disabled="disabled" name="GPA" size=21></td>
</tr>
<tr> 
  <td class="style1">Verdict:</td>
  <td class="style6"><input type=text disabled="disabled" name="V" size=21></td>
</tr> 
</table>
</center>
</form>
</html>

Thanks again Traevel!^_^
Cedric

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.