complete example of using the jquery autocomplete with ColdFusion
Hi,
have any one tried the code from this link: http://www.jensbits.com/2010/03/18/jquery-ui-autocomplete-with-coldfusion/?
i created table with 2 columns:
Colnumn # 1: abbrev : TX, CA
Column # 2: state: Texas, California
and try the code from the link above but it did do anything for me, i am not sure if didn't have it right, can you please help?
Thanks
Lisa
============
<!----index.cfm--->
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function() {
$('#abbrev').val("");
$("#state").autocomplete({
source: "states.cfm",
minLength: 2,
select: function(event, ui) {
$('#state_id').val(ui.item.id);
$('#abbrev').val(ui.item.abbrev);
}
});
$("#state_abbrev").autocomplete({
source: "states_abbrev.cfm",
minLength: 2
});
});
</script>
<cfdump var="#form#" label="Form Fields" />
<form action="index.cfm" method="post">
<fieldset>
<legend>jQuery UI Autocomplete Example - ColdFusion Backend</legend>
<p>Start typing the name of a state or territory of the United States</p>
<p class="ui-widget"><label for="state">State (abbreviation in separate field): </label>
<input type="text" id="state" name="state" /> <input readonly="readonly" type="text" id="abbrev" name="abbrev" maxlength="2" size="2"/></p>
<input type="hidden" id="state_id" name="state_id" />
<p class="ui-widget"><label for="state_abbrev">State (replaced with abbreviation): </label>
<input type="text" id="state_abbrev" name="state_abbrev" /></p>
<p><input type="submit" name="submit" value="Submit" /></p>
</fieldset>
</form>
<!---states.cfm--->
<cfset returnArray = ArrayNew(1) />
<cfquery name="qryStates" dataSource="remoteNetwork">
Select * from states where state like <cfqueryparam value="%#URL.term#%" cfsqltype="cf_sql_varchar">
</cfquery>
<cfloop query="qryStates">
<cfset statesStruct = StructNew() />
<cfset statesStruct["id"] = id />
<cfset statesStruct["label"] = state />
<cfset statesStruct["abbrev"] = abbrev />
<cfset ArrayAppend(returnArray,statesStruct) />
</cfloop>
<cfoutput>
#serializeJSON(returnArray)#
</cfoutput>
</cfif>
