DK-Flag Erik Østergaard - JScript Calculator / JScript regnemaskine Go to Home Page
Calculator Bottom of This Page

This calculator works as an ordinary pocket calculator. Use only the period (.) as a valid decimal separator.

JScript Calculator

This is a demonstration calculator implemented in JavaScript. You must have a JavaScript-capable browser for this to work.

Because we want this calculator to be interactive, both receiving and processing input, we embed the "calculator"-table within FORM tags. Each button is specified as an input source. The FORM tag lacks a METHOD attribute. Normally this attribute would be required, specifying either POST or GET, depending on how input is to be passed to an application through CGI. The FORM tag here also lacks an ACTION attribute, which would normally tell the browser the location of the CGI program for processing the form. Since our form will be processed on the client side, neither of these attributes is required. Instead our FORM simply has a NAME attribute, enabling the script to distinguish forms by name later on. The INPUT tags within this form also differ from the usual tags. TYPE is specified simply as "button", which is not one of the normal options. Also, the INPUT tag contains a new attribute, onClick. This pair, button and onClick, specifies one means of passing input to the script. For the "Jcalc" script this is the only input source used. Because browsers ignore HTML tags and attributes they do not understand, these new elements will not cause particular problems with the appearance of the calculator.

Note that the Nselect function, for example, could well be reused in other applications that require numerical input. The Nselect function builds up a larger numerical string from individual number-button clicks.

JScript Calculator is a Javascript Program -- adapted from a sample calculator Javascript app from Mark Stone. You can see the JavaScript by using View Source.

   Top of This Page
   Go to Home Page