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

The Archive Base Latest Questions

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

I have simple jQuery UI autocomplete, which was working and now it’s not. The

  • 0

I have simple jQuery UI autocomplete, which was working and now it’s not. The code is as follows:

<html>
    <head>
    <script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.8.23.custom.min.js"></script>

    <script type="text/javascript">
        $(function() {
            $( "#city" ).autocomplete({
                source: function( request, response ) {
                    var cities = new Array();
                    cities.push({"label" : "Chicago", "value" : 1});
                    cities.push({"label" : "Houston", "value" : 2});
                    response(cities);
                },
                focus: function(event, ui) {
                    //console.log(ui.item.label);
                    $(this).text(ui.item.label);
                    //console.log($(this).text());
                    event.preventDefault();
                    //console.log($(this).text());
                },
                select: function(event, ui) {
                    //console.log($(this).text());
                    event.preventDefault();
                    //console.log($(this).text());
                }
            });
        });
    </script>
    </head>
    <body>
      <input id="city" />
    </body>
</html>

I am using the focus handler to show the label in the textbox instead of the value (which is what the autocomplete does by default). What is happening now is that the textbox is showing neither label nor value, it is showing the value that I have typed (say ‘Chi’)

This was working but now it’s not. I thought it was because I had included some other javascript and there was a function name clash. But I moved it to a separate HTML as you can see above and it’s still not working.

BTW if I uncomment those console log statements and from the dropdown I select Chicago, then all of them print Chicago.

This seems like some silly mistake somewhere but has me stumped. Any suggestions?

EDIT 1: BTW, if I remove the focus and select handlers then the autocomplete works with its default functionality.

EDIT 2: Would be great if someone can test this on their own computer

  • 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-11T07:49:51+00:00Added an answer on June 11, 2026 at 7:49 am

    There are a couple of changes from default functionality which you appear to be attempting here.

    1. You would like the “completed” variable to be previewed in the main input when it is selected
    2. You would like the label, not the value, to be shown when a selection has been made.

    The reasons that neither of these are currently working are related and simple: <input> fields only have a value associated with them, not a separate “label” and “value”. When you select an “autocomplete” option from the list, it is the “value”, which gets filled in.

    For point 1, the part which is being updated by the focus: event, just replace .text(...) with .val(...), as that is the attribute of the <input> field which you actually want to update:

    focus: function(event, ui) {
        $(this).val(ui.item.label);
        event.preventDefault();
    },
    

    For point 2, as you actually want the field to be filled in by the label, not the value, you could just fill in the same text for both (the default if a flat array is given):

    source: function( request, response ) {
        var cities = new Array();
        cities.push("Chicago");
        cities.push("Houston");
        response(cities);
    },
    

    Remember that autocomplete is always optional. All you need to fill in for the value: is something which you back-end can fully disambiguate. That could be an id, but it usually makes sense to use something which the user might have typed in on their own. Of course, if you’re doing that, it may also make sense to use ui.item.value instead of ui.item.label in the focus: event, as well.

    With the source made sane as above, you can drop the select: event entirely.

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

Sidebar

Related Questions

The below code is very simple. I have a jQuery autocomplete bound to an
I have a jQuery UI which is doing simple autocomplete function. Autocomplete is coming
So, I'm NOT using the jQuery UI AutoComplete as I have a simple application.
I have a simple jQuery script that I'm trying to build upon but I
I have a simple jquery flipcard animation - http://jsfiddle.net/gGAW5/36/ Now the way this flip
I have pretty simple jquery code : $(document).ready(function(){ $('img.marqFl').on({ mouseenter: function() { $(this).animate({height: 300},
I have a simple jquery animation on a div, which is inside a div,
I have a simple jQuery code that runs on a web page that has
I have a simple jquery/ajax request to the server which returns the structure and
I have this very simple jQuery function: $(.milestone-in-tree).live({ mouseenter: function() { setTimeout( $.ajax({ type:

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.