SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Predictive Text

  1. #1
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Predictive Text

    Hey,

    I want to use predictive text on my website for a list of dropdown options. For example, if i have alist of States, town city etc. I want the text box to predict what the user will type.

    See this example:-

    http://www.glassdoor.com/survey/star...Survey=REVIEWS

    Try typing something in the employer box..

    First of all, is this free to use? if not i need to talk to my client. If it is, how can i use it?

    Regards
    Billy

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should be pretty familiar with using javascript and ajax.

    But, the gist of it is that you either use keyup or simply poll the text field for changes. When it changes, you fire off an ajax request to a serverside script that does something like
    Code:
    select something
    from sometable
    where something like 'goog%'
    limit 10
    return the results and then update the dom with javascript.

    The above just does a simple substring search on the left of the string. This won't give you much as far as "predicting" what they will type, but it will return a list of possibilities. If you want to get into trying to provide the most likely 10 predictions, it can get pretty complicated. But, for making state/city suggestions, the simple left substring search should work pretty good because city/state names tend to be fairly unique, or at least enough to the point where offering up 5-10 suggestions will be likely to have a match in it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •