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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:53:07+00:00 2026-05-20T02:53:07+00:00

I have a Textbox with the id text (#text) with has an autocomplete like

  • 0

I have a Textbox with the id text (“#text”) with has an autocomplete like that:

$("#text").autocomplete(data);

this works fine.
Now i want three things:

a) If the user clicks on a autocomplete option -> search for that

b) If the user types something and an autocomplete action is shown but he clicks somewhere else -> search for that string he typed

c) If the user types something that has to autocomplete and clicks somewhere else (change event) -> search for that string he typed

Sounds easy to me but i cant get it to work. At the Moment i have something like that:

$("#text").result(function(e) {
    $("#text").trigger("change");
});
$("#text").change(function(e){
    $(".x").load(...);  
});

If i dont use that trigger, than a) does not work at all, if i type “a” and click on an autocomplete option, “#text” contains “a” in the change function. So the change fires before the value is changed. My thought is that this would be no problem as then shortly after that the result fires the trigger again now with the right value, but that does not happen.

Like this it sometimes works but not all the time. I tried lots and lots of stuff and some worked better and some worse but nothing was correct all the time. How do i do this the right way?

  • 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-20T02:53:07+00:00Added an answer on May 20, 2026 at 2:53 am

    I’ve never worked with the autocomplete that you’re using, but here’s a tool you should include in your JavaScript problem-solving toolbox.

    When an event fires immediately before another event and you need to wait for the second event to complete before processing the first, use setTimeout(...). There are times where it looks like a delay is required, but more often than not, you just need a few nested calls to setTimeout(…, 0)

    function onIdle(fn, loops) {
      loops = loops == null ? 1 : loops;
      if (loops > 0) {
        setTimeout(function() { onIdle(fn, loops - 1); }, 0);
      } else {
        fn();
      }
    }
    

    With the above code, you could do something like this in your onChange handler:

    onIdle(function() { ... }, 5);
    

    That would call setTimeout consecutively, 5 times. On the fifth time (after which the other event should have completed), you can process the change and use the new value.

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

Sidebar

Related Questions

I have to align a textbox and some text, at about 30 degrees, like
I want to have a text box that the user can type in that
I have an autocomplete text box that users can type an item code into
I have a textbox with the Text property bound to a dataset column with
I have a textbox and a link button. When I write some text, select
I have this bit of script to widen a text box on mouseover and
I have an ASP.NET user control that contains a text box control and a
In my application I have TextBox in a FormView bound to a LinqDataSource like
I have three TextBox controls on the page <asp:TextBox ID=TextBox1 runat=server AutoPostBack=True OnTextChanged=TextBox_TextChanged TabIndex=1>
I have a text box whose Text property has a TwoWay MultiBinding with UpdateSourceTrigger

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.