We help IT Professionals succeed at work.
Get Started

Javascript and XHTML building a calculator

527 Views
Last Modified: 2013-11-19
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

Comment
Watch Question
This problem has been solved!
Unlock 2 Answers and 4 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE