If we want to use AJAX so that the visitor can remain on the same page while the search parameters are continuously refined, then the AUTOSUGGEST attribute of the CFINPUT tag can be utilized. This way when requesting the user to provide data it makes it easier to pull consistent statistics from that data when it is uniform. If many of the appointment remarks are going to start off with the same phrase, then we don't necessarily want to make them type that portion over and over.
<cfform>
<cfinput type="text" name="AppointRemark" autosuggest="cfc:SuggestAppointRemark.getSuggest({cfautosuggestvalue})" maxresultsdisplayed="15" showautosuggestloadingicon="false" />
</cfform>
The AUTOSUGGEST triggers the SuggestAppointRemark CFC, specifically the getSuggest function, sending it the text typed into the AppointRemark field in our CFM page. As the letters are typed, the GetRemark query is populated with the information and returns an array of possibilities (limited to 15 in this example by the MAXRESULTSDISPLAYED attribute of the CFINPUT tag). If you add the matchcontains="true" attribute into the CF INPUT you will get a list containing the letter groups you type into the field instead. That is fine for short lists, but can be cumbersome for longer lists of information.
<cffunction name="getSuggest" access="remote">
<cfargument name="SuggestRemark" type="string" required="true">
<cfset var GetRemark="">
<cfscript>
GetRemark=QueryNew("Remark");
QueryAddRow(GetRemark, 4);
QuerySetCell(GetRemark, "Remark", "Apples", 1);
QuerySetCell(GetRemark, "Remark", "Almonds", 2);
QuerySetCell(GetRemark, "Remark", "Alaska", 3);
QuerySetCell(GetRemark, "Remark", "Aladin", 4);
</cfscript>
<cfreturn ListToArray(ValueList(GetRemark.Remark))>
</cffunction>
When you run the form and type the letter A in the field, you will be presented with a list of all possibilities in our pseudo database. Add the letter L and the list drops off Apples. Add the letter A and the list drops off Almonds.
If you find this post useful please leave a comment and let me know how you used the information.
In this example, it will prevent the error message "the specified cfc suggestappointremark could not be found".