Avatar of Thomas Turner
Thomas Turner
Flag for United States of America asked on

Javascript and XHTML building a calculator

What I’m trying to do,

I have 3 classes and each class has a drop down list of A, B, C, D, F and each letter corresponds with a number 1-4. + a place to put your name

I need to finger out how to do this
When you click My GPA I need it to add all the numbers up and divide them by 3 and output that and you name on another page.

I’m very new to JavaScript

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>GPA Calculator</title

<script type="text/javascript">
<!-- 
function GPA(name, GPA)
{

GPA = ParseInt(GPA)

Class1 = parseInt(Class1);
Class2 = parseInt(Class2);
Class3 = parseInt(Class3);
var sum = (Class1 + Class2 + Class3)/(3);
var str = "<h4>" + name + "</h4><p> Your GPA is " + sum + ".</p>;
document.write(str);
}
//-->
</script>
</head>

<body>
<form>
      <p>GPA Calculator</p>

      <p>Name:
      <input name="name" type="text" id="name" size="20" maxlength="20" />
      </p>


<table>
<tr>
    <td>Class 1</td>
    <td>
 <select name="Class1">
<option value="4">A</option>
<option value="3">B</option>
<option value="2">C</option>
<option value="1">D</option>
<option value="0">F</option>
</select>
</form>
</td>
  </tr>
<tr>
    <td>Class 2</td>
    <td>
 <select name="2">
<option value="4">A</option>
<option value="3">B</option>
<option value="2">C</option>
<option value="1">D</option>
<option value="0">F</option>
</select>
</form>
</td>
  </tr>
<tr>
    <td>Class 3</td>
    <td>
 <select name="Class3">
<option value="4">A</option>
<option value="3">B</option>
<option value="2">C</option>
<option value="1">D</option>
<option value="0">F</option>
</select>
</form></td>
  </tr>
</table>
<p>
      <input type="button" value="My GPA" onclick="GPA(this.form.name.value,this.form.GPA.value)" />
      </p>

</form>
</body>
</html>

Open in new window

Web Languages and StandardsHTMLJavaScript

Avatar of undefined
Last Comment
Graceful_Penguin

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Graceful_Penguin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Michel Plungjan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Thomas Turner

ASKER
Graceful_Penguin, when you put this line in

0/*this field does not exist:

what field is it talking about?

Thank you all for your help.
Graceful_Penguin

The GPA field that you tried to get a value from with this code : this.form.GPA.value
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck