jQuery autocomplete let the label trigger a js function

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
lovelf
Forum Contributor
Posts: 153
Joined: Wed Nov 05, 2008 12:06 am

jQuery autocomplete let the label trigger a js function

Post 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.
lovelf
Forum Contributor
Posts: 153
Joined: Wed Nov 05, 2008 12:06 am

Re: jQuery autocomplete let the label trigger a js function

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: jQuery autocomplete let the label trigger a js function

Post by pickle »

Check the jquery UI docs, there is a "select" event & subsequent option.

http://jqueryui.com/demos/autocomplete/
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply