Simplified to match your code ...
Code:
<HTML>
<head>
<title>Simple Calculator</title>
<script type="text/javascript">
var ans = 0;
function calc(action){
var x=document.getElementById("tb1").value * 1;
var y=document.getElementById("tb2").value * 1;
switch (action) {
case '+' : ans = x+y; break;
case '-' : ans = x-y; break;
case '*' : ans = x*y; break;
case '/' : ans = x/y; break; // still need division by zero check
default : alert(action+' is invalid operation');
}
}
function evalit(){
document.getElementById("tb3").value= ans;
}
</script>
</head>
<BODY>
<form name="form1">
<input type="text"size="2" id="tb1"/>
<br/><input type="radio" name="r" value="*" onClick="calc(this.value)"/>*
<br/><input type="radio" name="r" value="-" onClick="calc(this.value)"/>-
<br/><input type="radio" name="r" value="+" onClick="calc(this.value)"/>+
<br/><input type="radio" name="r" value="/" onClick="calc(this.value)"/>/
<br/>
<input type="text"size="2" id="tb2"/>
<br />
<input type="button" value="=" name="eq" onClick="evalit()">
<input type="text"size="2" name="box1" id="tb3"/>
</form>
</BODY>
</HTML>
Bookmarks