Page 1 of 1

jQuery autocomplete let the label trigger a js function

Posted: Mon Feb 27, 2012 3:11 pm
by lovelf

Code: Select all

	 			$("#jTagLabel").autocomplete({
					source: [
				{
					label: "aardvark", 
					value: "aardvark"
				},
				{
					label: "apple",
					value: "apple"
				},
				{
					label: "<i>atom</i>",
					value: "atom"
				}
			]
,html:true
				});
I have the following autocomplete, I want to add an action to the label, for example selecting an option triggers a javascript function, but how? I have HTML enabled on the labels as well, I managed to trigger a js function with an onclick event for each of the labels but it only works when the user clicks on a label, not if it is selected with the enter key. What I want is to trigger a javascript function with a second value other than the label itself to make some magic.

Thanks.

Re: jQuery autocomplete let the label trigger a js function

Posted: Mon Feb 27, 2012 3:35 pm
by lovelf
This guy has a solution but I don't understand Coldfusion nor am I using the autocomplete in the exact same way with a json callback.
http://www.petefreitag.com/item/756.cfm

Re: jQuery autocomplete let the label trigger a js function

Posted: Tue Feb 28, 2012 5:43 pm
by pickle
Check the jquery UI docs, there is a "select" event & subsequent option.

http://jqueryui.com/demos/autocomplete/