Hi All,
I have couple of question and need some help on my task. Im stucked and need to see my error. Please help.
Basically, I just need to an autosuggest on my input text.
(form.cfm)
Here's my component file : (S_Company.cfc) in a directory "cfc"
My table is table_company
Columns: id, d_company_name, abbrev
Cannot make it work.Problem might be in jquery or in my CFC. Please help.
Thank you very much.
I have couple of question and need some help on my task. Im stucked and need to see my error. Please help.
Basically, I just need to an autosuggest on my input text.
(form.cfm)
Code:
<html>
<head>
<link rel="stylesheet" type="text/css" href="[URL unfurl="true"]http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css">[/URL]
<script src="[URL unfurl="true"]http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>[/URL]
<script src="[URL unfurl="true"]http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>[/URL]
<title>Untitled Document</title>
<script>
$(function() {
$("#company").autocomplete({
//source: "states.cfm",
source: "cfc/S_Company.cfc",
minLength: 1,
select: function(event, ui) {
//$('#id').val(ui.item.id);
//$('#abbrev').val(ui.item.abbrev);
}
});
});
</script>
</head>
<cfsilent>
<cfinvoke component="cfc.S_Company" method="autosuggest">
<cfinvokeargument name="searchPhrase" value="#url.searchPhrase#">
</cfinvoke>
</cfsilent>
<body>
<!--- <cfinvoke component="_cfc/autocomplete" method="BrandAffiliations"returnvariable="BrandAffiliations"/> --->
<form action="index.cfm" method="post">
<p class="ui-widget"><label for="company">Company Name : </label>
<input type="text" id="company" name="company" />
</p>
<p><input type="submit" name="submit" value="Submit" /></p>
</form>
</body>
</html>
Here's my component file : (S_Company.cfc) in a directory "cfc"
Code:
<cfcomponent>
<cffunction name="autosuggest" access="remote">
<cfargument name="searchPhrase" type="any" />
<cfset returnArray = arrayNew(1) />
<cfset var id = 'id' />
<cfset var d_company_name = 'd_company_name' />
<cfquery name="qryCompany" dataSource="db_source">
Select *
FROM table_company
WHERE d_company_name like <cfqueryparam value="%#Arguments.searchPhrase#%" cfsqltype="cf_sql_varchar">
</cfquery>
<cfloop query="qryCompany">
<cfset compStruct = StructNew() />
<cfset compStruct["id"] = id />
<cfset compStruct["d_company_name"] = d_company_name />
<cfset ArrayAppend(returnArray,compStruct) />
</cfloop>
<cfoutput>
#serializeJSON(returnArray)#
</cfoutput>
</cffunction>
</cfcomponent>
My table is table_company
Columns: id, d_company_name, abbrev
Cannot make it work.Problem might be in jquery or in my CFC. Please help.
Thank you very much.