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 7862811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:17:21+00:00 2026-06-02T23:17:21+00:00

I am using Autocomplete function in jQuery (much like Facebook). As I mention in

  • 0

I am using Autocomplete function in jQuery (much like Facebook).
As I mention in image, I don’t want duplicate values in the Autocomplete.

see demo http://wharsojo-js.googlecode.com/files/jquery.autocompletefb-0.1.1.zip

Here is my code:

jQuery.noConflict();

        jQuery(document).ready(function()

        {

              var i=document.getElementById('autocomplete_1').innerHTML;

             var acfb =

                        jQuery("ul.first").autoCompletefb(

                        {

                            urlLookup:i.split(','),

                            deleteimgurl:"deleteimg/",

                        }

                        );  

                     jQuery("#acfb-input" ).blur(function()

                     {

                        document.getElementById('auto_complete_text').value=acfb.getData(); 

                    }); 

                 });

enter image description here

  • 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-06-02T23:17:23+00:00Added an answer on June 2, 2026 at 11:17 pm

    Hiya working demo http://jsfiddle.net/Yvnfx/ or without alert: http://jsfiddle.net/Yvnfx/1/ Taking care of deletion as well http://jsfiddle.net/wbQZU/4/

    So behavior wise: if you selected java the aotocomplete will not show java in available tags.

    key is to create an array of usedItems which and then make a new array = existing array - used items

    Jquery code

      **var usedItems = []**
    :
    :// then
    source: function(request, response) {
    
          //===<> Read: build new array with = AvailableTagsArray - UsedItemArray
                 var newNonDuplicatetag = $.grep(availableTags, function(el){return $.inArray(el, usedItems) == -1});
    
                // delegate back to autocomplete, but extract the last term
                response($.ui.autocomplete.filter(
                newNonDuplicatetag, extractLast(request.term)));
            },
    

    Full Jquery code

    $(function() {
        var usedItems = [];
    
        var availableTags = [
            "ActionScript",
            "AppleScript",
            "Asp",
            "BASIC",
            "C",
            "C++",
            "Clojure",
            "COBOL",
            "ColdFusion",
            "Erlang",
            "Fortran",
            "Groovy",
            "Haskell",
            "Java",
            "JavaScript",
            "Lisp",
            "Perl",
            "PHP",
            "Python",
            "Ruby",
            "Scala",
            "Scheme"
            ];
    
        function split(val) {
            return val.split(/,\s*/);
        }
    
        function extractLast(term) {
            return split(term).pop();
        }
    
    
        $("#tags")
        // don't navigate away from the field on tab when selecting an item
        .bind("keydown", function(event) {
            if (event.keyCode === $.ui.keyCode.TAB && $(this).data("autocomplete").menu.active) {
                event.preventDefault();
            }
        }).autocomplete({
            minLength: 0,
            source: function(request, response) {
                 var newNonDuplicatetag = $.grep(availableTags, function(el){return $.inArray(el, usedItems) == -1}); 
                // delegate back to autocomplete, but extract the last term
                response($.ui.autocomplete.filter(
                newNonDuplicatetag, extractLast(request.term)));
            },
            focus: function() {
                // prevent value inserted on focus
                return false;
            },
            select: function(event, ui) {
                var terms = split(this.value);
                // remove the current input
                terms.pop();
                // add the selected item
                usedItems.push(ui.item.value);
                alert(usedItems[1]);
                terms.push(ui.item.value);
                // add placeholder to get the comma-and-space at the end
                terms.push("");
                this.value = terms.join(", ");
                return false;
            }
        });
    });
    

    Updated Jquery code (WIth the case of – when you delete the item
    then it should due added back to available tags

    $(function() {
        var usedItems = [];
    
        var availableTags = [
            "ActionScript",
            "AppleScript",
            "Asp",
            "BASIC",
            "C",
            "C++",
            "Clojure",
            "COBOL",
            "ColdFusion",
            "Erlang",
            "Fortran",
            "Groovy",
            "Haskell",
            "Java",
            "JavaScript",
            "Lisp",
            "Perl",
            "PHP",
            "Python",
            "Ruby",
            "Scala",
            "Scheme"
            ];
    
        function split(val) {
            return val.split(/,\s*/);
        }
    
        function extractLast(term) {
            return split(term).pop();
        }
    
    
        $("#tags")
        // don't navigate away from the field on tab when selecting an item
        .bind("keydown", function(event) {
            if (event.keyCode === $.ui.keyCode.TAB && $(this).data("autocomplete").menu.active) {
                event.preventDefault();
            }
        }).autocomplete({
            minLength: 0,
            source: function(request, response) {
    
       //to handle the case when dleted We want to add the code back to available tags.
                var tempTags = $('#tags').val().split(',');
           var newNonDuplicatetag1 = $.grep(usedItems, function(el){return $.inArray(el, tempTags) != -1}); 
         // build new available tag -(minus) used tag here                                                           
          var newNonDuplicatetag = $.grep(availableTags, function(el){return $.inArray(el, newNonDuplicatetag1) == -1}); 
                // delegate back to autocomplete, but extract the last term
                response($.ui.autocomplete.filter(
                newNonDuplicatetag, extractLast(request.term)));
            },
            focus: function() {
                // prevent value inserted on focus
                return false;
            },
            select: function(event, ui) {
                var terms = split(this.value);
                // remove the current input
                terms.pop();
                // add the selected item
                usedItems.push(ui.item.value);
               // alert(usedItems[1]);
                terms.push(ui.item.value);
                // add placeholder to get the comma-and-space at the end
                terms.push("");
                this.value = terms.join(", ");
                return false;
            }
        });
    });
    
    
    ​
    ​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using jQ UI Autocomplete with multiple values My function looks like that mailto_input.bind( keydown,
I'm using the autocomplete function in jQuery UI 1.8.6. And I want to highlight
I'm using a .Jquery autocomplete function and I'm tring to figure out where can
I'm using the jQuery UI's autocomplete function on a search on my site. When
I have an input box for which I am using the Jquery autocomplete function.
I am using jQuery autocomplete, and want to have a separate PHP file to
I am using jQuery autocomplete pluggin . I have the following code $().ready(function() {
I'm using the jquery autocomplete function to enhance the user-friendliness of my site. It
Currently using the JQuery UI autocomplete list function JQuery UI - Autocomplete . I
I am using jQuery's autocomplete plugin to fill the textbox element. I want the

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.