SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Predictive Text

Hybrid View

  1. #1
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    0 Post(s)
    0 Thread(s)

    Predictive Text


    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:-

    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?


  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    0 Post(s)
    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
    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.


Posting Permissions

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