Advertisement
jasch

Untitled

Oct 12th, 2011
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CFM PAGE ///////////////
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Untitled Document</title>
  7. <link rel="stylesheet" type="text/css" href="../Scripts/jquery/jquery-ui-custom2012/css/custom-theme/jquery-ui-1.8.16.custom.css" />
  8.  
  9. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
  10. <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
  11. <script type="text/javascript">
  12. $(function() {
  13.     $("#category").autocomplete({
  14.         source: "service2.cfc?method=searchcategories&returnformat=json",
  15.         select:function(event,ui) {
  16.             $("#catid").val(ui.item.id)
  17.         }
  18.     });
  19. });
  20. </script>
  21.  
  22. </head>
  23.  
  24. <body>
  25. <form action="Test-AutoSuggest.cfm" method="post"> 
  26. category: <input name="category" id="category" />
  27. <input name="catid" id="catid" type="hidden">
  28. <input type="submit" value="Submit">
  29. </form>
  30.  
  31. <cfif not structIsEmpty(form)>
  32.     <cfdump var="#form#" label="Form">
  33. </cfif>
  34. </body>
  35. </html>
  36.  
  37.  
  38. CFC ///////////////////
  39. <cfcomponent>
  40. <cffunction name="searchCategories" access="remote">
  41.     <cfargument name="term" type="string">
  42.     <cfset var q = "">
  43.     <cfset var result = []>
  44.     <cfquery name="q" datasource="#application.datasource#">
  45.     select ContactID as id,
  46.     CONCAT(LastName, ', ', FirstName) as value
  47.     from contacts
  48.     where LastName like <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.term#">
  49.     </cfquery>
  50.     <cfloop query="q">
  51.         <cfset result[arrayLen(result)+1] = {}>
  52.         <cfset result[arrayLen(result)]["id"] = query.id[i]>
  53.         <cfset result[arrayLen(result)]["value"] = query.value[i]>
  54.     </cfloop>
  55.     <cfreturn result>
  56. </cffunction>
  57. </cfcomponent>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement