Home arrow HTML arrow Page 5 - Function Details for a Web Page Calculator
HTML

Function Details for a Web Page Calculator


Welcome to the third part of a six-part series on building a web page calculator. In the previous part I gave you the skeletons of our two standard calculator functions. But there are fine details to these functions that we have to examine and appreciate. We start with the showNum() function.

Author Info:
By: Chrysanthus Forcha
Rating: 4 stars4 stars4 stars4 stars4 stars / 2
March 18, 2009
TABLE OF CONTENTS:
  1. · Function Details for a Web Page Calculator
  2. · First Segment continued
  3. · The Second Code Segment
  4. · Second Code Segment continued
  5. · The Third Code Segment

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Function Details for a Web Page Calculator - The Third Code Segment
(Page 5 of 5 )

The third code segment is:


//remove leading zero

var strToTest = document.getElementById('CI1').value;

if (/^0d/.test(strToTest))

document.getElementById('CI1').value = strToTest.replace(/^0/,"")


This is not a case for the switch statement. From the explanation of all the code I have given above, we see that there can be one leading zero for the number on the display when there is no decimal point. I decided that any such leading zero should be removed. This is the behavior of physical calculators.

This code segment removes the leading zero. It first of all copies the content of the display to the strToTest local variable. It then uses a regular expression to see if there is a leading zero. If there is, it removes it from the value of the strToTest variable. Then it copies the result back to the display.

We have done enough for this part of the series. We continue in the next part.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
HTML ARTICLES

- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5
- BBC Adopts HTML 5, Mozilla Addresses Issues
- Advanced Sticky Footers in HTML and CSS
- HTML and CSS Sticky Footers
- Strategy Analytics Predicts HTML5 Phones to ...
- HTML5 Guidelines for Web Developers
- Learning HTML5 Game Programming
- More Engaging CSS3 and HTML Background Effec...
- Engaging HTML and CSS3 Background Effects
- More Web Columns with CSS3 and HTML
- Columns with CSS3 and HTML
- Creating Inline-Block HTML Elements with CSS
- Drag and Drop in HTML5: Parsing Local Files

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



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