Hey ddtpmyra,
First you need to understand what PHP, Java, and JavaScript are. Besides languages, they have nothing else in common.
PHP is non-compiled script that is executed and run on the server. The output is plain text (or HTML).
Java is a compiled programming language that stands alone and runs on the computer it is executed on.
JavaScript is a scripting language in a web page that is executed within the user's web browser.
My recommendation for you is to read tutorials. One site that helps you with all of this and much more (and is a site we all basically started with) is
www.w3schools.com Start there.
As to your problem, I would do this in JavaScript because it's trivial, quicker (no refresh), and pretty easy.
To get you interested, here's some code:
-
-
<html>
-
<head><title>Calculator</title></head>
-
<script language="JavaScript" type="text/JavaScript">
-
function calSum()
-
{
-
var num1 = parseInt(document.getElementById('firstNum').value);
-
var num2 = parseInt(document.getElementById('secNum').value);
-
document.getElementById('result').innerHTML = (num1 + num2);
-
return;
-
}
-
</script>
-
<body>
-
First Number: <input type="text" value="" name="firstNum" id="firstNum" /><br/>
-
Second Number: <input type="text" value="" name="secNum" id="secNum" /><br/>
-
<input type="button" value="Calculate Sum" onclick="calSum();" /><br/>
-
Answer: <span id="result"></span>
-
</body>
-
<html>
-
-
put that in a file, name it calculator.html and open it with your web browser.
to change and mess around with it, open it in notepad, change then save it. Refresh your browser to see your changes.
Good Luck!
Dan