tags:

views:

51

answers:

3

Hi all, I have an interesting question, i hope..I have a textarea in my form..when a user comes to enter values in it it displays some cached values in an autocomplete format..thats fine..I want to call an ajax function after the user selects such a cached value in it..so that the ajax call should pass this selected value..so my question is on which can i get the final selected value, so i call ajax at that time,... i tried with onblur etc, but not worked..

help please.. thanks in advance...

A: 

If the user chooses by clicking, you want a 'click' handler on the element the user is selecting (or a containing element).

If the user can select in other ways, eg by the keyboard, then you'll need to observe other events as well.

Colin Fine
I don't think selecting an element from an autocomplete lookup counts as a `click` event on the text input.
Pekka
user cAn select in all ways
soorajthomas
Pekka is right...i tried and found that..
soorajthomas
No, it isn't a click on the text input. It is a click on the element selected. In scriptaculous AutoComplete (which is the only one I have used) the options are <li> elements inside a <div> which is hidden until the autocomplete is used: you can put a 'click' handler on that <div>. I don't know how the autocompleter you are using organises its data, but if it is displaying items they have DOM elements, and in principle you can set event handlers on those elements.
Colin Fine
A: 

You mean you want to detect if the user selects a value the browser's native Autocomplete lookup, instead of typing it in themselves?

I'm certain there is no event to catch this.

The only workaround that comes to mind is analyzing the keypress events the user makes in the input field. If the keys entered do not match the full string that is in the text field, and no onpaste event was fired, it stands to reason that the value was selected from an Autocomplete.

This is going to be tough to implement, though, and by no means 100% reliable.

Pekka
the user can directly enter the values also..all cases are possible
soorajthomas
is this possible with jquery in an easy way...
soorajthomas
@sooraj not in an easy way, no. I doubt there exists a plugin for this - you'd have to build it yourself.
Pekka
is there any otherway to find this, becos data is populated in textarea after selection, so why this will not fire in any events...or in an indirect way, can we fire..by putting some div or something like..?
soorajthomas
@sooraj I don't think so. You would probably have to use your own Autocomplete function to do this.
Pekka
A: 

As Pekka said above, there will likely be browser-specific events to handle for this kind of functionality, but it is possible.

For IE, check out http://stackoverflow.com/questions/343192/why-does-the-javascript-onchange-event-not-fire-if-autocomplete-is-on for a reference to the "onpropertychange" event within IE.

For Firefox, it looks like others have solved it through a combination of onBlur and onFocus (see http://stackoverflow.com/questions/865490/firefox-capture-autocomplete-input-change-event).

If you do come up with a cross-browser solution, please let us know!

brianghig