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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:01:35+00:00 2026-05-23T22:01:35+00:00

I have the following jquery Autocomplete form that pulls data in from a local

  • 0

I have the following jquery Autocomplete form that pulls data in from a local XML file.

It works fine and displays the data as it should, but how can I return a specific data value into the search field?

For example, when searching for London, the auto complete returns values thus:

London Heathrow Airport, UK –

Which is great – BUT I’d like it populate the actual search field by grabbing a specific XML ID, (The airport code = IATA) and add ONLY that to the search field – like this:

LHR

How can I achieve that ?

Here’s the jquery code

@Nicola Peluchetti

Thanks for your help and answer – this is what I got from your comments – but it’s not working – did I miss something ?

$(document).ready(function() {
    var myArr = [];

    $.ajax({
        type: "GET",
        url: "airports.xml", 
        dataType: "xml",
        success: parseXml,
        complete: setupAC,
        failure: function(data) {
            alert("XML File could not be found");
            }
    });

function parseXml(xml)
{
//find every query value
    $(xml).find("state").each(function()
{
    //you are going to create an array of objects
    var thisItem = {};
    var thisItem[label] = $(this).attr("label") + ',  ' + $(this).attr("country");
    var thisItem[value] = $(this).attr("iata");
    myArr.push(thisItem);
});
} 



    function setupAC() {
        $("#city").autocomplete({
                source: myArr,
                minLength: 3,
                select: function(event, ui) {
            //replace the label with the value
            $(this).val(ui.value);
        }



        });
    }
});

and here’s the airports.xml file snippet

<states>
<state label="London Heathrow" iata="LHR" country="UK" />
<state label="Syndey" iata="SYD" country="Australia" />

….

And the search form snippet

<label for="city">From</label></td>

  • 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-23T22:01:35+00:00Added an answer on May 23, 2026 at 10:01 pm

    EDIT (i modified the answer according to the comments) – You could modify this function:

    function parseXml(xml)
    {
        //find every query value
            $(xml).find("state").each(function()
        {
            //you are going to create an array of objects
            var thisItem = {};
            thisItem['label'] = $(this).attr("label") + ',  ' + $(this).attr("country");
            thisItem['value'] = $(this).attr("iata");
            myArr.push(thisItem);
        });
    } 
    

    EDIT 2 – you don’t need this second part: autocomplete automatically replace the “label” with the “value” if you specify both of them in the object

    semplified fiddle here : http://jsfiddle.net/7cLxD/1/

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

Sidebar

Related Questions

I have a site with a form with autocomplete using jquery. It works fine,
I am begging to use jquery. I have the following call that works in
do you know a jQuery Autocomplete Plugin that has the following features. I have
I have the following jquery which reads from the excellent geonames.org web service: $('#<%=txtFindMyCity.ClientID%>').autocomplete(http://ws.geonames.org/searchJSON,
I have the following jQuery code: $.ajax({ type: POST, url: /search, data: $(form).serialize(), success:
I have the following JQuery code that worked perfect in C#/Asp.net 2.0 to call
Following on from my previous two questions: How to make jQuery autocomplete execute a
I have the following code (inherited from someone): <div class=feedback>&nbsp;</div> <form onsubmit=return false autocomplete=off>
I am using jQuery autocomplete pluggin . I have the following code $().ready(function() {
I have tried to use the following code to retrieve the data from 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.