Link to home
Start Free TrialLog in
Avatar of Thomas Turner
Thomas TurnerFlag 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

ASKER CERTIFIED SOLUTION
Avatar of Graceful_Penguin
Graceful_Penguin
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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.
The GPA field that you tried to get a value from with this code : this.form.GPA.value