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
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


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

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