Home arrow HTML arrow Coding a Web Page Calculator
HTML

Coding a Web Page Calculator


Welcome to the second part of a six-part series on how to build a calculator for your web page. In the previous part, we got into the basics of setting up the calculator's layout and what functions we want it to have. In this part, we will begin to code the functions.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 4
March 11, 2009
TABLE OF CONTENTS:
  1. · Coding a Web Page Calculator
  2. · Code Basics
  3. · The showNum() Function
  4. · The operator() Function
  5. · Explanation of the operator() Function

print this article
SEARCH DEVARTICLES

Coding a Web Page Calculator
(Page 1 of 5 )

Pressing the Buttons

You can either press a button by clicking it or by using the keyboard. Pressing by clicking requires you to give each button the onclick attribute. I included the onclick attribute for each button in the previous part of this series. I will address using the keyboard later in the series.

In this part of the series, a button is pressed by clicking. When a button is clicked, the onclick event is triggered (calls a function). We shall look at the functions in this part of the series.

Standard Calculator User Requirements

In this section I explain the requirements from the user's point of view.

  • When the calculator is opened, the initial value in the display is zero.

  • As soon as you type a digit, the digit typed replaces the zero.

  • When a number appears on the display, clicking a digit joins the number on the display to the right.

  • When you click the +, -, X or / key, the next number typed replaces the number on the display. This should result in the +, -, X, or / operation.

  • When the equal sign button is clicked, the result replaces the number (group of digits) on the display.

  • When the M+ (store in memory) button is clicked, the number on the display is stored in memory. After this, clicking another digit replaces the number on the display.

  • You can erase the display by pressing a button.

  • When the equal sign is clicked, the operation (+, - X or /) combining the previous number on the display and the present number is evaluated. The result replaces the present number on the display.


blog comments powered by Disqus
HTML ARTICLES

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials