Jump to content

Simple Calculator


DamoMoran

Recommended Posts

Hey guys, making a simple calculator.. Want to make the displaying text field show a zero after you add or subtract etc instead of adding the symbol.. but cant seem to figure it out.. heres what i got! <html><head><script type="text/javascript"></script></head><body><FORM NAME="Calc"><TABLE BORDER=4><TR><TD><INPUT TYPE="text" NAME="Input" Size="16"><br></TD></TR><TR><TD><INPUT TYPE="button" NAME="one" VALUE=" 1 " OnClick="Calc.Input.value += '1'"><INPUT TYPE="button" NAME="two" VALUE=" 2 " OnCLick="Calc.Input.value += '2'"><INPUT TYPE="button" NAME="three" VALUE=" 3 " OnClick="Calc.Input.value += '3'"><INPUT TYPE="button" NAME="plus" VALUE=" + " OnClick="Calc.Input.value += ''"><br><INPUT TYPE="button" NAME="four" VALUE=" 4 " OnClick="Calc.Input.value += '4'"><INPUT TYPE="button" NAME="five" VALUE=" 5 " OnCLick="Calc.Input.value += '5'"><INPUT TYPE="button" NAME="six" VALUE=" 6 " OnClick="Calc.Input.value += '6'"><INPUT TYPE="button" NAME="minus" VALUE=" - " OnClick="Calc.Input.value += ' - '"><br><INPUT TYPE="button" NAME="seven" VALUE=" 7 " OnClick="Calc.Input.value += '7'"><INPUT TYPE="button" NAME="eight" VALUE=" 8 " OnCLick="Calc.Input.value += '8'"><INPUT TYPE="button" NAME="nine" VALUE=" 9 " OnClick="Calc.Input.value += '9'"><INPUT TYPE="button" NAME="times" VALUE=" x " OnClick="Calc.Input.value += ' * '"><br><INPUT TYPE="button" NAME="clear" VALUE=" c " OnClick="Calc.Input.value = ''"><INPUT TYPE="button" NAME="zero" VALUE=" 0 " OnClick="Calc.Input.value += '0'"><INPUT TYPE="button" NAME="DoIt" VALUE=" = " OnClick="Calc.Input.value = eval(Calc.Input.value)"><INPUT TYPE="button" NAME="div" VALUE=" / " OnClick="Calc.Input.value += ' / '"><br></TD></TR></TABLE></FORM></body></html> Thanks in advance, :)

Link to comment
Share on other sites

You'll need to use a function to do that instead of having all of the code inline. If the function sees an operator then it will need to store the current values in variables before it resets the field so that it can get that value later to do the calculation.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...