Home arrow HTML arrow More on the Keyboard for a Web Page Calculator
HTML

More on the Keyboard for a Web Page Calculator


In this fifth part of a six-part series on building a web page calculator, we shall see how to use the keyboard with the calculator. The event involved is the onkeypress event, which we saw in the last part of the series. For an element to respond to the event, it has to have focus. With some browsers, if all of the elements that have to respond to the keyboard have the same function, and are in the same group (on the calculator), you only have to give one of the elements focus. This is the case with my browser.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
April 01, 2009
TABLE OF CONTENTS:
  1. · More on the Keyboard for a Web Page Calculator
  2. · The processKey(e) Function
  3. · Details of the processKey(e) Code segments
  4. · The Second if (else if) block
  5. · The Fourth if (else if) block

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
More on the Keyboard for a Web Page Calculator
(Page 1 of 5 )

Modifying the Initialization Function

The initialization function is the showCalc() function. When the web page is opened, and you click the Use Calculator button, this function is called. The function opens the calculator and does any initialization necessary. The only initialization it has to do is give focus to the zero digit button. So add the following line at the bottom of the showCalc() function.


document.getElementById('B0').focus();


Handling Keyboard Presses

When you press any key on the keyboard, the function processKey(e) is called. This function is added to do all the processing of keyboard issues.


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 8 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials