PhpRiot
Download This Article
Download this article in PDF format with all listings and files.

Price: $5.00 AUD
(Approx. $4.10 USD)

More information
Related Books
The Essential Guide to Dreamweaver CS3 with CSS, Ajax, and PHP

The Essential Guide to Dreamweaver CS3 with CSS, Ajax, and PHP

With over 3 million users worldwide, Adobe's Dreamweaver is the most popular web development...

The Essential Guide to Dreamweaver CS4 with CSS, Ajax, and PHP (The Essential Guide)

The Essential Guide to Dreamweaver CS4 with CSS, Ajax, and PHP (The Essential Guide)

Dreamweaver CS4 is a massive step forward in terms of integration with the rest of the CS4 suite...
Browse Articles
Ajax (4), APC (1), CAPTCHA (1), CSS (3), Debugging (1), File Upload (1), Google (3), Google Maps (2), JavaScript (12), JSON (2), MVC (1), MySQL (7), onbeforeunload (1), OOP (1), PHP (28), PhpDoc (1), PostgreSQL (6), Prototype (11), Reflection (1), RFC 1867 (1), Robots (1), Scriptaculous (1), SEO (1), Sessions (1), SimpleXML (1), Smarty (5), SOAP (1), SPL (1), Templates (2), W3C (1), XHTML (1), Zend Framework (1), Zend_Search_Lucene (1)

PhpRiot Newsletter
Your Email Address:

Cloning Google Suggest With Ajaxac

Implementing The Application Javascript

Now we need to piece the whole thing together and make it work. Some of the JavaScript created here will be created dynamically using AjaxAC, while some of it will be utility functions that we will place in googlesuggestclone.js.

First things first though, we need to work out exactly how this will all work before it can be implemented.

It will need to work something along the lines of:

  1. Do nothing until user enters some text in the query input box.
  2. User enters some text
  3. Start a timer counting down from N milliseconds
  4. If user presses another key before time expires, start the timer again
  5. If timer expires:
    1. Sanitize string (only letters, numbers and spaces, periods or underscores are valid)
    2. If the remaining string has more than 0 characters, send a request using the getsuggestions action
  6. Receive results and populate the search-results div with them

Now, in addition to monitoring the input box for input, we need to monitor the search-results div for any keypresses. Keypresses allow the user to select a different suggested option. Additionally, the user can use the mouse to select the alternate options.

This is the application at its most basic level. There are more advanced things that can be implemented, such as caching of suggestion results, but perhaps this will be left for another day.

In This Article


Tagged in , , ,