HTML
  Home arrow HTML arrow Page 2 - Building a Web Page Calculator
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
HTML

Building a Web Page Calculator
By: Chrysanthus Forcha
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-03-04

    Table of Contents:
  • Building a Web Page Calculator
  • Technical Interpretation of the Page
  • The Standard Calculator Controls
  • Code For Controls

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Building a Web Page Calculator - Technical Interpretation of the Page


    (Page 2 of 4 )

    I use XHTML norms for the design. The basic XHTML page in our project is:


    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>

    <title>Page with Calculator</title>


    </head>

    <body onclick="removeCalc()">


    </body>

    </html>


    The above code has the following elements: XML, DOCTYPE, HTML, HEAD and BODY. The components of the calculator will be contained in a DIV element. There will be a button that, when clicked, causes the calculator to appear. This is the basic content of the BODY element.


    <div id="Calc" onclick="calcJustClicked = true;">

    </div>

    <button type="button" onclick="calcJustClicked = true; showCalc()">Use Calculator</button>


    The DIV element has the ID "Calc." The button has the title "Use Calculator." It has an onclick event whose meaning we shall see soon.

    The value of the CSS display property of the calculator (DIV) is given an initial value of "none." Layering is used; when the calculator is to be displayed, it appears in front of every other element. So the DIV element for the calculator is given the absolute value for its CSS position property, and a z-index value of 2. The BODY element is given the absolute value for its position property, and a z-index value of zero. This is the basic code for the CSS:


    <style type="text/css">

    body {position:absolute; z-index:0; background-color:#ff9933}

    div#Calc {position:absolute; display:none; background-color:brown; z-index:2}

    </style>


    When the button is clicked, the showCalc() function is called. This function changes the value of the CSS display property for the calculator (DIV) to "block;" the calculator is displayed as a result. When you click the BODY element, the removeCalc() function is called. This function changes the value of the CSS display property of the calculator (DIV) to "none;" the calculator disappears. Note that when this property is "none," the calculator (DIV) is off the screen. This is the basic JavaScript; I give further explanation below it:


    <script type="text/javascript">

    var calcJustClicked = false;

     

    function showCalc()

    {

    document.getElementById('Calc').style.display = "block";

    }


    function removeCalc()

    {

    if (calcJustClicked == false)

    {

    document.getElementById('Calc').style.display = "none";

    calcShown = false;

    }

    //reset the calcJustClicked boolean variable

    calcJustClicked = false

    }

    </script>


    The onclick attribute of the button is:


    onclick = "calcJustClicked = true; showCalc()".


    What is the use of the first statement "calcJustClicked = true;"? When you click the BODY element, a function is called to remove the calculator from the screen. When you click the button, another function is called to display the calculator.

    Now, when you click the BODY element, only one function is called. However, when you click the button, the BODY element is indirectly clicked. So, two events are triggered. These events oppose one another. The one from the button causes the calculator to be displayed. The one from the BODY, which follows immediately, causes the calculator to be removed. When we click the button, we want only the first event to take effect.

    When you click the button, the "calcJustClicked = true" statement first sets the calcJustClicked global variable to true, indicating that the button has just been clicked. When the opposing function from the BODY is immediately called, it first checks to see if calcJustClicked is true, with


    if (calcJustClicked == false)


    If it is true, it does not remove the calculator. However, before the opposing function completes its execution, it resets the calcJustClicked variable to false (the default value). In this way, when you next click the body element, the calculator will be removed.

    Now when the calculator is displayed, you will need to be clicking buttons on it. When you click the calculator, the BODY element will also receive the click (indirectly). In order to prevent the calculator from being removed, the calculator (DIV) has the attribute


    onclick="calcJustClicked = true;"


    This has the same effect as for the "Use calculator" button.


    More HTML Articles
    More By Chrysanthus Forcha


       · Oh no! not another push-button calculator...Is the one buit into every PC not...
       · It is good to have your own calculator, designed with the features you...
     

    HTML ARTICLES

    - Hello HTML 5, Goodbye Gears
    - Comparing Browser Response to Active Client ...
    - Testing Browser Response to Active Client Pa...
    - Active Client Pages: Completing the Code for...
    - ACP and Browsers: Setting up an Example
    - How Browsers Respond to Active Client Pages
    - Completing a Tree with Active Client Pages
    - HTML Form Verification and ACP
    - Building an ACP Tree
    - Completing an ACP 3D HTML Table Image Gallery
    - Building an ACP 3D HTML Table Image Gallery
    - A Multiple Page Image Gallery with Active Cl...
    - Building an Image Gallery with Active Client...
    - Concluding a Menu for All Browsers
    - A Vertical Menu for All Browsers







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 10 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek