Try this, I changed a bit.
PHP Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/JavaScript">
function compute(form){
var operator = document.getElementById('Select1').value;
if (operator =="add"){
function a_plus_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=a+b
form.ans.value = c
alert("your answer is: " + c)
}
Else if (operator == "minus"){
function a_minus_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=a-b
form.ans.value = c
alert("your answer is: " + c)
}
else if (operator == "multi"){
function a_times_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=a*b
form.ans.value=c
alert("your answer is: " + c)
}
else if (operator =="divide")[
function a_div_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=a/b
form.ans.value = c
alert("your answer is: " + c)
}
}
</script>
</head>
<body>
<div align ="center">
<form name="formx"><input type=text size=4 value=12 name="a">
<br />
<br />
<!--choose operation:
<input type="button" value=" + " onClick="a_plus_b(this.form)">
<input type="button" value=" - " onClick="a_minus_b(this.form)">
<input type="button" value=" x " onClick="a_times_b(this.form)">
<input type="button" value=" / " onClick="a_div_b(this.form)">
<!--cant get this to work right now, moving on -->
choose operation:
<select id="Select1" name="D1">
<option value="">Select an operation.</option>
<option value="add">+</option>
<option value="minus">-</option>
<option value="multi">*</option>
<option value="divide">/</option>
</select>
<br />
<br />
<input type="number" size=4 value=3 name="b">
<br />
</br>
<input id="submit" type="button" value="calculate" onClick="compute(this.form)"/>
<input type "number" value=0 name="ans" size=9>
</form>
</div>
</body>
</html>
Bookmarks