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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:49:11+00:00 2026-06-07T18:49:11+00:00

Imagine a json file with the following data: [ { color: red, value: #f00

  • 0

Imagine a json file with the following data:

[
    {
        color: "red",
        value: "#f00"
    },
    {
        color: "green",
        value: "#0f0"
    },
    {
        color: "blue",
        value: "#00f"
    },
    {
        color: "cyan",
        value: "#0ff"
    }
]

Using jQuery’s autocomplete method, I want it to be able to display the color as options to select and insert value on a input.

<input type="text" name="selector" id="selector" />

<input type="text" name="color" id="color" />
<input type="text" name="value" id="value" />

The above doesn’t need introductions. Selector for the search on the colors, input.color with color value and input.value with value value.

EDIT:
I have this JSON data:

[{
    "label": "Sec\u00e7\u00e3o 1",
    "value": "1"
}, {
    "label": "Sec\u00e7\u00e3o 2",
    "value": "2"
}, {
    "label": "Sec\u00e7\u00e3o 3",
    "value": "3"
}, {
    "label": "Sec\u00e7\u00e3o 4",
    "value": "4"
}]

and this HTML:

<input type="text" id="name" />
<input type="text" id="value" />

and this jQuery:

$(document).ready(function(){
    $("#name").autocomplete({
        source: "json.php",
        select: function (event, ui) {
            $("#name").val(ui.label);
            $("#value").val(ui.value);
        }
    });
});

I followed Andrew’s answer and it prompts me to select the data, but if I alert ui.labeland ui.value variables, it says ‘undefined’. What am I missing?

Edit2:
Let’s say I have this HTML:

<input type="text" class="name" />
<input type="text" class="value" />

<input type="text" class="name" />
<input type="text" class="value" />

Is it possible to handle multiple selectors with the same .autocomplete() method? Like, select the label I want using the input.name and only update the input.value next to it?

[input.name] [input.value]
^ I select       ^ updates the
  a label           value next to it
[input.name] [input.value]
^ this stays intact ^

  • 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-07T18:49:13+00:00Added an answer on June 7, 2026 at 6:49 pm

    Using a remote data source:

    $("#selector").autocomplete({
        source: function (request, response) {
             $.ajax({
                 url: "my_server_side_resource.php",
                 type: "GET",
                 data: request,
                 success: function (data) {
                     response($.map(data, function (el) {
                         return {
                             label: el.color,
                             value: el.value
                         };
                     }));
                 }
             });
        },
        select: function (event, ui) {
            // Prevent value from being put in the input:
            this.value = ui.item.label;
            // Set the next input's value to the "value" of the item.
            $(this).next("input").val(ui.item.value);
            event.preventDefault();
        }
    });
    

    Tweak the $.ajax call as needed. This example will generate requests to your PHP resource that look like this:

    my_server_side_resource.php?term=xyz

    If you have control over your server-side code, you could change the data that’s returned to look like this:

    [
        {
            label: "red",
            value: "#f00"
        }, /* etc */
    ]
    

    You can simply use a string, the name of your server-side resource as the source:

    $("#selector").autocomplete({
         source: "my_server_side_resource.php",
         select: /* same as above */
    });
    

    Check out the remote with JSONP example for a full example using a server-side resource.

    Edit: See this example for a working demo using local data: http://jsfiddle.net/SMxY6/

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

Sidebar

Related Questions

Is it possible to generate xcdatamodel file from json? Here's how i imagine it
Imagine I have following table: NAME DATE OTHER_CONTANT 'A' '2012-06-05' 'baz' 'A' '2012-06-04' 'bar'
Imagine you have two views with code like the following: controller_a/a.html.erb <%= content_tag(:div) do
Imagine I've got a database with lots of data, from which users can search.
We have published a json api to share data between a few domains. We
Imagine I did upload a 50mb file to S3. After uploading it completely, the
Imagine I've got a data object that makes sense in an OO model, but
Before Anything: $.getJSON back button showing JSON return data not the page did not
I have a csv file that contains XML entries. Imagine that each XML entry
Using the Newtonsoft.Json library, imagine I have got public class Test { public Object

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.