Quantcast
Channel: Adobe Community: Message List - ColdFusion
Viewing all articles
Browse latest Browse all 21760

Re: autosuggest

$
0
0

Hi

 

Create a .cfc name it as autosuggest.cfc

 

<cfcomponent output="false">

 

    <!--- Lookup used for auto suggest --->

    <cffunction name="findPark" access="remote" returntype="string">

        <cfargument name="search" type="any" required="false" default="">

       

        <!--- Define variables --->

        <cfset var local = {} />

       

        <!--- Query Location Table --->

        <cfquery name="local.query" datasource="cfdocexamples" >

            select        parkname

            from        parks

            where        parkname like <cfqueryparam cfsqltype="cf_sql_varchar" value="#ucase(arguments.search)#%" />

            order by    parkname

        </cfquery>

 

        <!--- And return it as a List --->

        <cfreturn valueList(local.query.parkname)>

    </cffunction>

 

</cfcomponent>

 

 

Now create a.cfm and name as demo.cfm

 

<!--- A simple form for auto suggest --->

<cfform action="autosuggest.cfm" method="post">

    Park Name:<br />

    <cfinput type="text" name="parkname" size="50" autosuggest="cfc:autosuggest.findPark({cfautosuggestvalue})" autosuggestminlength="1" maxresultsdisplayed="10" /><br /><br />

</cfform>

 

 

Place both of them in the webroot and run demo.cfm, you will get exactly the same results which you are looking for.

 

Hope it helps

 

Thanks

VJ


Viewing all articles
Browse latest Browse all 21760

Trending Articles