Creating applications using forms.
simple applications. Following is a simple calculator I created as an example.
Put this is the <head> tag.
I'm aware that parts of this are complex, but I wanted to show a
working example of an application. You will then need to add some html to your
page to interact with this script. View the source of this page to see what I've
done to create it. Simply, I've created a form called "calcform," a textbox
called "displaytext" and inputs with "onClick" events calling the above
functions. Each button with a number calls the "CalcNum" function with the
variable "NewNum" as a string of the number. Each operator calls the function
"ChangeOp" with the variable "NewOp" as the new operator (+,-,*,/).
There is also an equals sign which calls "CalcTot," and a Clear button which calls "CalcClear".
I have set up three main variables - "CurTot" which is a
floating point integer of the total, without the current number in the textbox.
"CurNum" is a string representation of the current number being entered (I.E. what
is in the textbox). Lastly "CurOp" gives a string of the operator that is going
to be used in the next operation.
Revised: January 26, 2001