Coldfusion and jquery autocomplete (using remote data)

Hi All.

I'd like to use an auto complete on a name field in my form using JQUERY and COLDFUSION.

I'm working from the http://www.simonwhatley.co.uk/examples/autocomplete/jquery/ tutorial but I seem to be coming unstuck, hence posting on here.

My code is provided below, i believe where im getting it wrong is the suggestion.cfm page where I actually call the data.

Can anyone shed some light on this for me?

thanks
<script type="text/javascript">
		$(document).ready(function() {
			$("#inputtest").autocomplete(
				"../suggestions.cfm",
				{
					minChars:2,
					delay:100,
					autoFill:false,
					matchSubset:false,
					matchContains:1,
					cacheLength:10,
					selectOnly:1
				}
			);

			
		});


</script>




<input type="text" name="inputtest" id="inputtest" />




<!--- code below for suggestions.cfm --->


<cfsetting enablecfoutputonly="true">
<cfparam name="q" default="" />
<cfquery name="qry" datasource="afm_fire">
SELECT em_name 
FROM afm.em
WHERE em_name LIKE <cfqueryparam value="#URL.q#%" cfsqltype="cf_sql_varchar" />
</cfquery>
<cfoutput query="qryGetCountry">
#qry.em_name##chr(10)#
</cfoutput>

Open in new window

LVL 2
CurtinPropAsked:
Who is Participating?
 
azadisaryevCommented:
it looks like your Application.cfm/cfc is outputting those lines. they, obviously, break the data returned from your page...

you could probably do something like this in your Application.cfm to disable it for suggestions.cfm page:

<cfif getfilefrompath(cgi.script_name) neq 'suddestions.cfm>
<!--- output page headers here --->
</cfif>

Azadi
0
 
azadisaryevCommented:
>> <cfquery name="qry"
>> <cfoutput query="qryGetCountry">

looks like you are outputting a wrong query?

Azadi
0
 
azadisaryevCommented:
you should also correct your <cfparam> tag:

<cfparam name="URL.q" default="">

Azadi
0
 
CurtinPropAuthor Commented:
My apologies, having made those changes I get an interesting result.

When a user starts to type into the input area, the autocomplete appears to work but it outputs an empty list of suggestions and when I select one of them it populates the input area with lines from the doctype and heading.

Im assuming its picking up lines of the source from suggestions.cfm??

I've attached an imagine showing the drop down, hopefully it makes sense.
auto-comp-screen1.jpg
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.