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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:59:55+00:00 2026-05-29T10:59:55+00:00

I am using jQuery Autocomplete to search a local database of cities. Here is

  • 0

I am using jQuery Autocomplete to search a local database of cities. Here is the code:

$('#txt_search_city').autocomplete({
    source: url,
    delay: 0,
    autoFocus: true,
    select: function( event, ui ) {
        $( "#id_city" ).val( ui.item.id );
        $(this).closest('form').submit();
    },
    focus: function( event, ui ) { event.preventDefault(); }
});

I’d like the first returned value to be selected by default (like it works on facebook). So essentially, if they just hit enter they will trigger the selection of the first result.

I thought that’s what autoFocus: true did, but it isn’t working. Not showing errors, just not selecting the first result.

Thoughts?

  • 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-29T10:59:55+00:00Added an answer on May 29, 2026 at 10:59 am

    Autofocus will highlight the first record..

    Your code would then just need to include autoFocus: true, like below:

    $('#txt_search_city').autocomplete({
        source: url,
        delay: 0,
        autoFocus: true,
        select: function( event, ui ) {
            $( "#id_city" ).val( ui.item.id );
            $(this).closest('form').submit();
        },
        focus: function( event, ui ) { event.preventDefault(); }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using jQuery autocomplete for a search field. When the autocomplete source returns a
Im using jQuery UI autocomplete. When i use a local variable as source it
I'm using jQuery autocomplete plugin from jQuery website calling the controller url which return
I'm using jQuery UI Autocomplete plug-in. I'm giving it an URL to make an
i will like to populate a Jquery autocomplete search with database items... rather than
I'm using the jQuery UI's autocomplete function on a search on my site. When
Here's my issue : using an autocomplete jQuery plugin, I'd like to avoid multiple
I am using jQuery UI autocomplete for a city search on my site. It
Im currently using the JQuery UI extension for its search autocomplete. However, I need
I am using jQuery UI Autocomplete to build a search interface. I have defined

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.