views:

28

answers:

1

I have a textbox that is wired up using jQuery UI 1.8.4 autocomplete. I have the select event wired up so when the user chooses an item from the list it calls another javascript function that issues an ajax request to save the data and update an XML document.

On the same textbox there is an onBlur event so that if the user manually types the data in and tabs off the textbox without choosing an autocomplete item it also performs the update.

When the user selects an item from the autocomplete list it causes onBlur to fire which overrides the select event, thus the only data that gets updated is whatever is in the textbox that the user typed, and since the select event doesn't fire the contents of the textbox don't get updated.

I've tried using the change event with the same results.

Is there a way to ensure the select event gets fired and also implement some functionality that will emulate an onBlur in the case where a user types the value in rather than selecting it?

Thanks.

A: 

The problem is when the user interacts with the autocomplete menu, the textbox looses focus and the blur event fires. There is no way to really detect if the user is in the autocomplete control unless the component tells you that.

If the autocomplete control you are using does not have methods to tell you when it is closed, than you are probably stuck with using a setTimeout to wait a bit before you fire your code.

epascarello
I used a combination of the two responses. I bound the events in a different order, which worked to some degree. The events were calling another method that uses AJAX as well. Since both events are firing off now the external script (not mine) was giving a not ready error. I used a setTimeout to keep them from clobbering each other with simultaneous requests. Thanks to you both!!!
David Good