Calculator


<HTML>
<HEAD>
<TITLE>Calculator</TITLE>
<SCRIPT type="text/javascript">
function calculate(form)
{
form.result.value=eval(form.result.value);
}
function addparameter(res,val)
{
res.value=res.value+val;
}
function bs(res)
{
var i,str="";
for(i=res.value.length;i>1;i--)
{
str+=res.value[res.value.length-i];
}
res.value=str;
}
</SCRIPT>
</HEAD>
<BODY>
<form>
<table border="1">

<tr>
<td colspan="5" align="center"><input type="text" name="result"></td>
</tr>

<tr>
<td><input type="button" name="button1" value="1" onClick="addparameter(form.result,this.value);"></td>
<td><input type="button" name="button2" value="2" onClick="addparameter(form.result,this.value);"></td>
<td><input type="button" name="button3" value="3" onClick="addparameter(form.result,this.value);"></td>
<td><input type="button" name="<-" value="<-" onClick="bs(form.result);"></td>
<td><input type="reset" name="clear" value="c" style="background:red"></td>
</tr>
<tr>
<td><input type="button" name="button4" value="4" onClick="addparameter(form.result,this.value);"></td>
<td><input type="button" name="button5" value="5" onClick="addparameter(form.result,this.value);"></td>
<td><input type="button" name="button6" value="6" onClick="addparameter(form.result,this.value);"></td>
<td><input type="button" name="add" value="+" onClick="addparameter(form.result,this.value);"></td>
<td><input type="button" name="substract" value="-" onClick="addparameter(form.result,this.value);"></td>
</tr>
<tr>
<td><input type="button" name="button7" value="7" onClick="addparameter(form.result,this.value);"></td>
<td><input type="button" name="button8" value="8" onClick="addparameter(form.result,this.value);"></td>
<td><input type="button" name="button9" value="9" onClick="addparameter(form.result,this.value);"></td>
<td><input type="button" name="multiply" value="*" onClick="addparameter(form.result,this.value);"></td>
<td><input type="button" name="divide" value="/" onClick="addparameter(form.result,this.value);"></td>
</tr>
<tr>
<td><input type="button" name="button0" value="0" onClick="addparameter(form.result,this.value);"></td>
<td><input type="button" name="dot" value="." onClick="addparameter(form.result,this.value);"></td>
<td><input type="button" name="leftparenthesis" value="(" onClick="addparameter(form.result,this.value);"></td>
<td><input type="button" name="rightparenthesis" value=")" onClick="addparameter(form.result,this.value);"></td>
<td><input type="button" name="cbutton" value="=" onClick="calculate(this.form);"></td>
</tr></table>

</form>
</BODY>
</HTML>

Comments

Popular Posts