I m trying to make simple windows look like calculator in java script. but when i add two numbers the result is zeroy . can anyone take a look on the code and can tell me where is problem?
<html>
<head>
<title></title>
<script type="text/javascript">
var res=0;var z="0";var o="o";var y=0;var x=0;
function calc(x)
{
if(z=="+" || z=="=" || z=="-") {document.form1.values.value=""; z=0;}
if(x!="+" && x!="-" && x!="=" && x!= "C") {document.form1.values.value+=x; y=parseint(document.form1.values.value);}
else o=x;
if(o=="+") {res += y;z=x;}
else if(o=="-") {res -= y;z=x;}
else if(o=="=") {document.form1.values.value=res; z=x;o="o";}
if(o=="C") {document.form1.values.value="";res=0;o="o";}
}
</script>
</head>
<body>
<table>
<form name="form1">
<tr><td colspan=3><input type="text" name="values" /></td></tr>
<tr><td><input type="button" value="1" onClick="calc(1)"/></td>
<td><input type="button" value="2" onClick="calc(2)"/></td>
<td><input type="button" value="3" onClick="calc(3)"/></td></tr>
<tr><td><input type="button" value="4" onClick="calc(4)"/></td>
<td><input type="button" value="5" onClick="calc(5)"/></td>
<td><input type="button" value="6" onClick="calc(6)"/></td></tr>
<tr><td><input type="button" value="7" onClick="calc(7)"/></td>
<td><input type="button" value="8" onClick="calc(8)"/></td>
<td><input type="button" value="9" onClick="calc(9)"/></td></tr>
<tr><td><input type="button" value="+" onClick="calc('+')"/></td>
<td><input type="button" value="0" onClick="calc(0)"/></td>
<td><input type="button" value="-" onClick="calc('-')"/></td></tr>
<tr><td colspan="2"><input type="button" value="C" onClick="calc('C')"/></td>
<td><input type="button" value="=" onClick="calc('=')"></td></tr>
</form>
</table>
</body>
</html>