spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column58


The Doc Dialer, Part 2: A Browser Independent Version

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

Event Handling

The events in this application are all handled by the numPressed() function. It handles three basic cases: the key 0, the key *, and the numeric keys 2 to 9:

function numPressed(digit) {
  if (digit == 0) {  // clear
    currentTrie = tree;
    outputStringToDisplay(welcomeStr);
  }
  else if (digit == 10) {  // enter new
         enterNewName();
		 currentTrie = tree;
       }
       else if (digit >= 2 && digit <= 9) {
               if (currentTrie[digit]) {
			     currentTrie = currentTrie[digit];
                 updateBoard(currentTrie);
                 printDisplay();
			   }
            }
  clearDisplayIndex();
}

The clear signal is given by the 0 key. We set the global variable currentTrie to the top of the trie data structure and display the welcome message:

if (digit == 0) {  // clear
  currentTrie = tree;
  outputStringToDisplay(welcomeStr);
}

When the * key is pressed, we start the prompt cycle with the user and we also initialize currentTrie:

if (digit == 10) {  // enter new
  enterNewName();
  currentTrie = tree;
}

During normal keying of the phone keys, we check if we can descend and we do the actual descending if possible. Once we descend a level, we call the updateBoard() function recursively. We also print the found names:

if (digit >= 2 && digit <= 9) {
  if (currentTrie[digit]) {
    currentTrie = currentTrie[digit];
    updateBoard(currentTrie);
    printDisplay();
  }
}

Next: How to make the code browser-independent

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


Created: February 28, 2000
Revised: April 26, 2000

URL: http://www.webreference.com/js/column58/9.html