Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 491271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:59:39+00:00 2026-05-13T01:59:39+00:00

I’m implementing a AJAX autocomplete/autosuggest feature, and not only do I want to do

  • 0

I’m implementing a AJAX autocomplete/autosuggest feature, and not only do I want to do the usual show suggestions that are similar to what the user typed, but I’d like to let the user do partial completions to save typing.

So, imagine my dictionary has these values in it: “green apple”, “green pear”, “green fruit”, “blue sky”, “blue water”, “blue wake”.

If the user types in “g”, the suggestions should be “green apple”, “green pear”, “green fruit”, and I’d like to let the user hit TAB or something to update his query to “green “, then they could type “a” and they’d get completed to “green apple”.

I’m trying to model this after linux shell command line completion.

Can you recommend a control/script that does this? Or a modification/customization of an existing control?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T01:59:39+00:00Added an answer on May 13, 2026 at 1:59 am

    This specific type of autocompletion isn’t supported in popular autocompletion plugins (for jQuery, Scripty…) because usually those provide a drop-down UI for choosing the wanted match.

    So let’s suppose we haven’t got an out-of-the-box solution. Boo-ho. How hard can it be to code it up?

    // takes a text field and an array of strings for autocompletion
    function autocomplete(input, data) {
      if (input.value.length == input.selectionStart && input.value.length == input.selectionEnd) {
        var candidates = []
        // filter data to find only strings that start with existing value
        for (var i=0; i < data.length; i++) {
          if (data[i].indexOf(input.value) == 0 && data[i].length > input.value.length)
            candidates.push(data[i])
        }
    
        if (candidates.length > 0) {
          // some candidates for autocompletion are found
          if (candidates.length == 1) input.value = candidates[0]
          else input.value = longestInCommon(candidates, input.value.length)
          return true
        }
      }
      return false
    }
    
    // finds the longest common substring in the given data set.
    // takes an array of strings and a starting index
    function longestInCommon(candidates, index) {
      var i, ch, memo
      do {
        memo = null
        for (i=0; i < candidates.length; i++) {
          ch = candidates[i].charAt(index)
          if (!ch) break
          if (!memo) memo = ch
          else if (ch != memo) break
        }
      } while (i == candidates.length && ++index)
    
      return candidates[0].slice(0, index)
    }
    

    Test page here — it should work in normal browsers. For supporting IE use event listening from prototype.js, jQuery or other.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.