permaculture playing cards
The moose likes HTML, CSS and JavaScript and the fly likes how google gives suggestions? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how google gives suggestions?" Watch "how google gives suggestions?" New topic

how google gives suggestions?

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Following is the line form source of google suggestions:

Here, I am not seeing any event (onKeyUp or onKeyPress) associated with this search textbox, then how suggestions are coming when we type something in it?

Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
It is an autocomplete using the XMLHttpRequest Object (Ajax)

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33121

It's probably being set in the JavaScript library. There is a technique I read about in PPK on JavaScript that favors this as it allows the HTML to be presentation only. The JavaScript sets itself up as the even handler for form elements. This makes sense for AJAX as you would want all the AJAX code to be in one place.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63862

Jeanne is correct. It is very common in Ajax applications to have JavaScript instrument the HTML DOM elements under script control rather than doing so in the HTML markup itself.

This allows for cleaner, modular code and is easier for the page author since the script handles all the nitty gritty details of setting up the elements correctly.
[ November 23, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: how google gives suggestions?
It's not a secret anymore!