#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2015
    Posts
    2
    Rep Power
    0

    form autosuggest (cfc and jquery) help


    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)
    Code:
    <html>
    <head>
    	 <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>
    
    <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>
    
    <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.
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,307
    Rep Power
    971
    "Cannot make it work" doesn't really help. Is there a browser/JS error? Server-side error? JSON/data format error?

IMN logo majestic logo threadwatch logo seochat tools logo