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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:27:43+00:00 2026-06-11T09:27:43+00:00

Requirement: I’d like a jQuery autocomplete element that allows the user to pick an

  • 0

Requirement:

I’d like a jQuery autocomplete element that allows the user to pick an item and set the display field and a hidden field with the selected value. But I would also like the field and the hidden field to be cleared when the input field receives focus by the user.

Problem:

The problem I’m facing is that when the user selects an item it’s almost like jQuery is executing the onSelect function and then sending the focus to the input field again which fires my focus() event (and therefore clearing my selection).

Problem Browser:

IE8 , works in Chrome. Did not try others.

Attempted fixes:

  • I have tried setting the focus to another element in the select()
    function. It did put the focus on that element but only after
    focussing on the input field
  • Tried both event.preventDefault() and event.stopPropagation() in the
    select() method. Did not work.
  • Blur didnt work either.

Workarounds:

I guess I can change the clearing to be on click instead of on focus, but this is not what I want.

Similar stackoverflow thread:

jquery autocomplete remove focus after suggest

Code:
Here is my code:

$(function () {
    $("#autosuggest").autocomplete({
        source: "my server path",
        minLength: 3,
        select: function (event, ui) {
            if (ui.item) {
                $("#autosuggest").val(ui.item.value);                    
                $("#hidden").val(ui.item.id);                                                                                
            }
        }
    });
    $("#autosuggest").focus(function () {
        $("#hidden").val("");
        this.value = "";
    });

});
  • 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-11T09:27:44+00:00Added an answer on June 11, 2026 at 9:27 am

    The problem is: when you click on an autocomplete suggestion, the focus shifts to that dropdown menu, ever so shortly, to return to your input afterwards. Do you still get this problem if you choose the autocomplete suggestion by using the arrow-down button? If you do not, then this is the problem.

    The only way I can see to fix this is not to make it a focus event after all, but I think I know why you don’t want to make it a click event: you also want to capture tabbing into the field.

    Solution: make it a click handler, and add a ‘keyup’ handler that executes the click handler handler if the key was a tab (arrow-down etc are still allowed).

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

Sidebar

Related Questions

Requirement is like: I want to take input values from user in frame but
My requirement is that i have a .php page that has to display some
My requirement is that user performing alter CANNOT be sysadmin (it can have all
My requirement is like that, I have a WebView control in my view i
My requirement is just to display a set of values retrieved from database on
Requirement : Should update MySQL database with that of MS Sql Server updates which
Requirement:- File1 has contents like - ABCD00000001,\some\some1\ABCD00000001,Y,,5 (this indicates there are 5 file in
requirement is, both field must be equal, what would you do declare @var datetime
Requirement : Return the element object. Problem : Using the code below, I expected
Requirement: I would like to interface my .NET application to a virtual webcam driver

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.