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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:34:21+00:00 2026-05-16T03:34:21+00:00

jQuery UI Autocomplete uses the variable names value , id and label to create

  • 0

jQuery UI Autocomplete uses the variable names “value“, “id” and “label” to create the drop down list. For example:

$("#cities").autocomplete({
    source: "backend/cities.php",
    minLength: 2,
    select: function(event, ui) {
        city = ui.item.id;
        region = ui.item.label;
        country = ui.item.value;
    }
});

the select: function is of course run when I click an item in the drop down list. However, I do not seem to have any control of the variable name (ui.item.label) it uses to populate the drop down list. The same applies when I click in the list and it enters the value (ui.item.value) into the input field.

Is there any easy way to change the default variable names that it uses to populate the drop down list and the input field?

  • The reason for this is that I am getting the JSON data from a remote server over which I have no control.

  • I don’t feel like editing the .js since it’s probable that they’ll release new versions of the .js regularly.

  • What I’d really like is to be able to edit the variables and their content between the callback from the server and the opening of the drop down menu.

Thank you for your time.

  • 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-16T03:34:21+00:00Added an answer on May 16, 2026 at 3:34 am

    I forgot to write my answer here. I figured it out. There’s a built-in success-handler in the autocomplete code. With it you can fetch the variables from the server and bundle them together into the proper ones (id, label, value). Use it like this:

    $("#cities").autocomplete({
        source: function(request, response) {
            $.ajax({
                url: "http://ws.geonames.org/searchJSON",
                dataType: "jsonp",
                data: {
                    featureClass: "P",
                    style: "full",
                    maxRows: 12,
                    name_startsWith: request.term
                },
                success: function(data) {
                    response($.map(data.geonames, function(item) {
                        return {
                            label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
                            value: item.name
                        }
                    }))
                }
            })
        },
        minLength: 2,
        select: function(event, ui) {
            // when clicked in list
        },
        open: function() {
            // triggered when the list is opened
        },
        close: function() {
            // triggered when the list is hidden
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use jquery.autocomplete , which uses a javascript regexp to highlight substrings in the
I am using jQuery Autocomplete to search a local database of cities. Here is
I'm using jQuery autocomplete for a search field. When the autocomplete source returns a
I have a jQuery text box autocomplete script which uses a PHP script to
The jquery ui autocomplete does not sort the items for mine automatically. It uses
I have a form field which uses Jorn Zaefferer's autocomplete jQuery plugin. If i
can someone recommand a good autocomplete or autosuggest that uses javascript or jquery? I
I am using the jquery.ui.autocomplete plugin, but I noticed when it searches, it uses
I'm using the jQuery autocomplete plugin to get a list of locations, which works
I've got a form that uses the jquery autocomplete UI plugin, http://jqueryui.com/demos/autocomplete/ , which

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.