Menu
I’m starting to write my GPA Calculator program over again this time using forms. [URL=”http://userpages.umbc.edu/~ofek1/gpacalc.html”]http://userpages.umbc.edu/~ofek1/gpacalc.html[URL=”http://userpages.umbc.edu/~ofek1/gpa.html”]http://userpages.umbc.edu/~ofek1/gpa.html[URL=”http://userpages.umbc.edu/~ofek1/gpacalc2.html”]http://userpages.umbc.edu/~ofek1/gpacalc…
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<i> </i> <meta http-equiv="expires" content="Sat, 13 Sept 2008 12:00:00 GMT">
<i> </i> <meta http-equiv="cache-control" content="no-cache">
<i> </i> <title>GPA Calculator</title>
<i> </i> <script type="text/javascript">
<i> </i> /***********************************************************************
<i> </i> ** ValidateCredits -
<i> </i> ** Input -
<i> </i> ** Output -
<i> </i> ***********************************************************************/
<i> </i> function ValidateCredits(validNumber)
<i> </i> {
<i> </i> validNumber = parseInt (validNumber);
<i> </i> if (validNumber <= 0 || validNumber >= 5 || isNaN(validNumber))
<i> </i> {
<i> </i> alert("Enter a positive integer from 1 to 4");
<i> </i> return false;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> return true;
<i> </i> }
<i> </i> }
<i> </i> /***********************************************************************
<i> </i> ** ValidatePoints -
<i> </i> ** Input -
<i> </i> ** Output -
<i> </i> ***********************************************************************/
<i> </i> function ValidatePoints(validNumber)
<i> </i> {
<i> </i> validNumber = parseInt (validNumber);
<i> </i> if (validNumber != 4 && validNumber != 3 && validNumber != 2 && validNumber != 1 && validNumber != 0)
<i> </i> {
<i> </i> alert("Enter a positive integer from 0 to 4");
<i> </i> return false;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> return true;
<i> </i> }
<i> </i> }
<i> </i> </script>
<i> </i></head><body>
<i> </i> <script type="text/javascript">
<i> </i> var semester = prompt("Enter the semester: ");
<i> </i> var numCourses = 0;
<i> </i> while (numCourses <= 0 || isNaN(numCourses))
<i> </i> {
<i> </i> numCourses = prompt("How many courses are you taking in the " + semester + " semester?");
<i> </i> }
<i> </i> numCourses = parseInt(numCourses);
<i> </i> while (numCourses > 0)
<i> </i> {
<i> </i> document.write('Number of credits: <input type="text" name="credits" onchange="return ValidateCredits(this.value)"><br> Grade points earned: <input type="text" name="points" onchange="return ValidatePoints(this.value)"> <br>');
<i> </i> numCourses = numCourses - 1;
<i> </i> }
<i> </i> </script>
<i> </i></body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<i> </i> <meta http-equiv="expires" content="Sat, 13 Sept 2008 12:00:00 GMT">
<i> </i> <meta http-equiv="cache-control" content="no-cache">
<i> </i> <title>GPA Calculator</title>
<i> </i> <script type="text/javascript">
<i> </i> /***********************************************************************
<i> </i> ** ValidateCredits -
<i> </i> ** Input -
<i> </i> ** Output -
<i> </i> ***********************************************************************/
<i> </i> function ValidateCredits(obj)
<i> </i> {
<i> </i> validNumber = parseInt (obj.value);
<i> </i> if (validNumber <= 0 || validNumber >= 5 || isNaN(validNumber))
<i> </i> {
<i> </i> alert("Enter a positive integer from 1 to 4");
<i> </i> obj.value = "";
<i> </i> obj.focus();
<i> </i> return false;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> return true;
<i> </i> }
<i> </i> }
<i> </i> /***********************************************************************
<i> </i> ** ValidatePoints -
<i> </i> ** Input -
<i> </i> ** Output -
<i> </i> ***********************************************************************/
<i> </i> function ValidatePoints(obj)
<i> </i> {
<i> </i> validNumber = parseInt (obj.value);
<i> </i> if (validNumber != 4 && validNumber != 3 && validNumber != 2 && validNumber != 1 && validNumber != 0)
<i> </i> {
<i> </i> alert("Enter a positive integer from 0 to 4");
<i> </i> obj.value = "";
<i> </i> obj.focus();
<i> </i> return false;
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> return true;
<i> </i> }
<i> </i> }
<i> </i> </script>
<i> </i></head><body>
<i> </i> <script type="text/javascript">
<i> </i> var semester = prompt("Enter the semester: ");
<i> </i> var numCourses = 0;
<i> </i> while (numCourses <= 0 || isNaN(numCourses))
<i> </i> {
<i> </i> numCourses = prompt("How many courses are you taking in the " + semester + " semester?");
<i> </i> }
<i> </i> numCourses = parseInt(numCourses);
<i> </i> while (numCourses > 0)
<i> </i> {
<i> </i> document.write('Number of credits: <input type="text" name="credits" onchange="return ValidateCredits(this)"><br> Grade points earned: <input type="text" name="points" onchange="return ValidatePoints(this)"> <br>');
<i> </i> numCourses = numCourses - 1;
<i> </i> }
<i> </i> </script>
<i> </i></body></html>
[CODE]totalPoints = totalPoints + (validNumber * numPoints);[/CODE]
[CODE]finalGPA = totalPoints / totalCredits;[/CODE]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<script type="text/javascript">
function totalizer() {
var validNumber = document.getElementsByName('credits');
var numPoints = document.getElementsByName('points');
var totalPoints = 0;
for(var i=0; len=validNumber.length, i<len; i++) {
if(!ValidateCredits(validNumber[i]) || !ValidatePoints(numPoints[i])) {
return;
}
totalPoints = totalPoints + (validNumber[i] * numPoints[i]);
}
alert(totalPoints);
}
</script>
<style type="text/css">
* {margin:0;padding:0;}
</style>
</head>
<body>
Number of credits: <input type="text" name="credits" onchange="return ValidateCredits(this)"><br> Grade points earned: <input type="text" name="points" onchange="return ValidatePoints(this)">
Number of credits: <input type="text" name="credits" onchange="return ValidateCredits(this)"><br> Grade points earned: <input type="text" name="points" onchange="return ValidatePoints(this)">
<button type="button" onclick="totalizer()">totalizer</button>
</body>
</html>
document.write('<form onsubmit="TotalPoints(); [COLOR="Blue"]return false;[/COLOR]">');
function TotalPoints()
{
<i> </i> var validNumber = document.getElementsByName('credits');
<i> </i> var numPoints = document.getElementsByName('points');
<i> </i> var totalPoints = 0;
<i> </i> for (var i=0; len=validNumber.length, i<len; i++)
<i> </i> {
<i> </i> if (!ValidateCredits(validNumber[i].value) || !ValidatePoints(numPoints[i].value))
<i> </i> {
<i> </i> return;
<i> </i> }
<i> </i> totalPoints = totalPoints + (validNumber[i].value * numPoints[i].value);
<i> </i> }
<i> </i> alert(totalPoints);
<i> </i> }
0.1.9 — BETA 5.22