Simple JQuery Autosuggest Dropdown ColdFusion Custom Tag

Before I found JQuery or JQuery found me and we fell into eternal blissful love, I wrote an autosuggest dropdown function which I have been using for years. It took almost a week to write and the code stretchs as far as my house to Minnesota. Recently I became stuck in the habit of simplifying my old pure JavaScript function to JQuery and this function caught me today. After around 20 lines of JavaScript and a couple of hours of testing and tweaking, this started to work better than my original function.

This is a very simple and lightweight autosuggest dropdown input combo function. All you have to do is wrap the custom tag around your html input tag and point to a data feed. Data feed is a delimited (the default delimiter is pipe |) word list, not a JSON array, so that won’t give you even the slightest bit of trouble when working with older CF servers. This tag doesn’t have “key stoke delay” or the ability to select items using the “key down”. That’s a small sacrifice I made to keep it as simple as it is. You can pass a number to [Wait] attribute, that will cause the drop down to wait until the user finish typing given amount of characters. Click here for an example.

Call :

   1: <cf_asug url="demo.cfc?method=state">
   2: <input type="text" name="myinput" />
   3: </cf_asug>
Show/Hide Line Numbers . Full Screen . Plain

Custom Tag:

Download (autosuggest.zip)
14 Comments :
Armando
Thursday 08 January 2015 03:35 PM
Sorry for the double post (now triple)...there was some kind of error when I hit "Comment" so I thought it didn't go...
Armando
Thursday 08 January 2015 03:34 PM
Just found this...looks fantastic! I'm kinda new sorry...I don't understand what is happening in the demo.cfc with the fake query for demo and real search. Let's say I have a table called "ppl" in my db with 20 names and I want these names to be the auto suggest content. What would my demo.cfc look like? Thanks for posting this!
Armando
Thursday 08 January 2015 03:33 PM
Just found this...looks fantastic! I'm kinda new sorry...I don't understand what is happening in the demo.cfc with the fake query for demo and real search. Let's say I have a table called "ppl" in my db with 20 names and I want these names to be the auto suggest content. What would my demo.cfc look like? Thanks for posting this!
Victoria
Thursday 27 March 2014 11:43 AM
I have to say that I LOVE YOU!! I have been trying every example from so many different websites and this is the only one I was able to get to work!!

Thanks a MILLION!!
Monique Boea
Wednesday 23 October 2013 12:01 AM
This doesn't work at all for me. I downloaded everything, put it on my server but it doesn't work

I am using CF 9
Thursday 24 October 2013 08:09 AM
Did you load jQuery in your page?
Gail
Tuesday 24 September 2013 02:26 PM
MORE HELP.. OK, so, I have a need for two such drop down lists base on TWO different text input value. I have a to and from address input fields. I am able to get the first to work, but cannot get the second one to work. I have used your example above and it works great for one, however, not with two. I have tried many things including duplicating the cfc and the asug.cfm and using them in the second field, with no luck. my coldfusion page looks like the following:
<cfset ddept = '99'>
<CFFORM METHOD="POST" ACTION="dropdown6.cfm">

Dept:  <cfoutput>#ddept#</cfoutput>

<strong>TO Building/Address:</strong>  
<cf_asug url="demo.cfc?method=state&passdept=#ddept#">
<CFinput type="text" name="Intext1" style="width:400px; font:Verdana; font-size:11px" />
</cf_asug>



<strong>FROM Building/Address:</strong>  
<cf_asug2 url="demo.cfc?method=state&passdept=#ddept#">
<CFinput type="text" name="Intext2" style="width:400px; font:Verdana; font-size:11px" />
</cf_asug2>


<P></P>
<P></P>



<cfoutput></cfoutput>
</CFFORM>
Andy
Tuesday 24 September 2013 03:25 PM
I would have thought that using two different methods in the cfc would work for you, making sure that, whatever route you choose to take, your dropdowns (id/name/cfc/method/) operate independently of one another. In any event, I abandoned this in favor of Ray Camden's example (http://tinyurl.com/kfr533f). Be sure to familiarize yourself with the jQuery autosuggest docs at the link provided there.

HTH,
Andy
Gail
Wednesday 25 September 2013 10:18 AM
I tried the example at the link above but it has a hard coded list in the code. Not sure how to use a query to get the drop down list i need. any suggestions.

Wednesday 25 September 2013 10:11 AM
Yes. JQuery UI had came a long way and getting that into the project helps a lot since it enables you to use other handy UI components like Calenders, etc..

Wednesday 25 September 2013 10:11 AM
Thanks, it was a bug and I fixed it.
Andy
Wednesday 18 September 2013 05:02 PM
Thank you. Do you know how to delay the autosuggest so that it doesn't activate right away, but rather when the user enters his third character? I don't necessarily need the entire dataset returned until the user starts to type. Thanks!
Wednesday 25 September 2013 10:12 AM
i added a new attribute [Wait].
Wednesday 12 October 2011 04:29 AM
Nice post, I like the way you teach in this post. thanks.