开发者

javascript event

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 wi开发者_如何转开发th onblur etc, but not worked..

help please.. thanks in advance...


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.


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.


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 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 FireFox capture autocomplete input change event).

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜