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

  • SEARCH
  • Home
  • 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 9044373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:58:10+00:00 2026-06-16T10:58:10+00:00

I’m trying to imitate this example: http://jqueryui.com/autocomplete/#multiple-remote Here’s are two of the target elements:

  • 0

I’m trying to imitate this example: http://jqueryui.com/autocomplete/#multiple-remote

Here’s are two of the target elements:

<input size="50" class="attr_values" name="collection" id="collection" />
<input size="50" class="attr_values" name="color" id="color" />

They send the “term” (search term the user types in) and the “attr_name” (e.g. collection or color) to a php script. Now I’m trying to figure out how to target the response data to the right input id.

Here’s my version of the script. I’ve attached .autocomplete to the attr_values class, and there are many instances of it on the page. So, in the source section, I added one element to the JSON array to send the id to the php script.

Now I need to figure out the other side of it. How do I target the response to the correct text box? I cannot figure out what response is doing.

$(document).ready(function() { 
    // 2 string parsing functions
    function split( val ) {
        return val.split( /,\s*/ );
    }
    function extractLast( term ) {
        return split( term ).pop();
    }


    $( '.attr_values' )
        // 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({
            source: function( request, response ) {
                $.getJSON( 'controllers/core_data/ajax/core_data.php', {
                    'attr_name' : this.element[0].id,
                    'term': extractLast( request.term )
                }, response );
            },
            search: function() {
                // custom minLength
                var term = extractLast( this.value );
                if ( term.length < 2 ) {
                    return false;
                }
            },
            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
                terms.push( ui.item.value );
                // add placeholder to get the comma-and-space at the end
                terms.push( '' );
                this.value = terms.join( ', ' );
                return false;
            }
        });

 });

EDIT:
To test the PHP script, right now I just have it doing this:

echo "[ 'foo','barf','mr T' ]";

SOLUTION:

I changed the above to:

echo '[ "foo","barf","mr T" ]';

And now it works. Very strange, I did not think quotes mattered in JSON.

  • 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-16T10:58:14+00:00Added an answer on June 16, 2026 at 10:58 am

    The response argument is a callback that you are simply meant to invoke with the final array of suggestions as an argument.

    So if I wanted to make an autocomplete that always suggests “red”, “green” and “blue”, I would make my source function look like this:

    source: function( request, response ) {
        response(["red", "green", "blue"]);
    },
    

    Assuming your PHP script returns an array of string values notated in JSON, what you are doing should work.

    The reason your PHP output was causing problems was that JSON uses double quotes as delimiters, not single quotes. ['foo','barf','mr T'] is invalid JSON.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.