The Doc Dialer, Part 2: A Browser Independent Version: Event Handling | WebReference

The Doc Dialer, Part 2: A Browser Independent Version: Event Handling


The Doc Dialer, Part 2: A Browser Independent Version

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 

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 

Next: How to make the code browser-independent

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

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

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