Skip to main content
April 29, 2011
Answered

ColdFusion Ajax Search Form ? Or Seach Filter ?

  • April 29, 2011
  • 1 reply
  • 6937 views

Sorry i am very new to ColdFusion and English is not my first language, please forgive me if have any mistake.

I am looking for some technique like search form or form filter.
This is a reference .
It is a hotel finding website.

My question is here, how to use coldfusion to create this kind of searching form with ajax?
Please give me some idea or tips , i will appreciate with you assist !

I have just get some idea on ajax search form with text.

<form>

Search: <input type="text" name="search">

<input type="button" value="Search">

</form>

<cfdiv bind="url:movieresults.cfm?search={search}">

</cfdiv>

It is depend on the url.
How about other like checkbox , select?

    This topic has been closed for replies.
    Correct answer talofer99

    This is the file of test.cfm

    <cfinvoke component="test2"

                     method="getFeatures"

                     returnvariable="Features">

    <form>

         <cfoutput query="Features">

         <input type="checkbox"

                      name="Feature_ID"

                      value="#Feature_ID#"

                       check="false">#Feature# <br />

         </cfoutput>

         <cfdiv bind="url:test2a.cfm?checkboxvalue={Feature_ID@click}">

    </form>

    ----------------------------------------------------------------------------------------------------------------------

    this is the file of test2a.cfm

    <cfparam name="url.checkboxvalue" default="">

    <cfset args = structnew()>

    <cfset args.Feature_ID = url.checkboxvalue>

    <cfinvoke component="test2"

                     method="sendFeatures" search="#args#" returnvariable="results">

    <cfoutput query="results">

    <tr>

    <td>#Restaurant_ID#</td>

    <td>#Name#</td>

    </tr>

    </cfoutput>

    ----------------------------------------------------------------------------------------------------------------------

    this is the cfc file

    <cfcomponent>

         <cfset ds = "Reservation">

         <cffunction name="getFeatures"

                        access="public"

                        returntype="Query">

         <cfset var Features="">

         <cfquery name="Features" datasource="#ds#">

         SELECT Feature_ID, Feature

         FROM Features

         </cfquery>

         <cfreturn Features>

         </cffunction>

         <cffunction name="sendFeatures"

                        returntype="Query"

                        access="public">

        

         <cfargument name="Feature_ID" type="any"  default="">

         <cfset var CheckBox ="">

         <cfquery name="CheckBox" datasource="#ds#">

         SELECT r.Name , r.Restaurant_ID, f.feature

         FROM Restaurants r, Bridge1_Restaurant_Features b, Features f

         where b.Feature_ID = f.Feature_ID AND b.Restaurant_ID = r.Restaurant_ID

         <cfif #ARGUMENTS.Feature_ID# IS NOT "">

         AND f.Feature_ID IN (#ARGUMENTS.Search.Feature_ID#)

         </cfif>

         GROUP BY r.Name

         </cfquery>

         <cfdump var="#arguments#">

         <cfreturn CheckBox>

         </cffunction>

    </cfcomponent>


    Its exacly what I thought it will be :

    Notice this :

    <cfinvoke component="test2"

      method="sendFeatures" argumentCollection="#args#" returnvariable="results">

    Compare to yours :

    <cfinvoke component="test2"

                     method="sendFeatures" search="#args#" returnvariable="results">

    Do you see the diffrence ?

    This is why you add a ARGUMNET.SEARCH.Feature_ID istead of ARGUMNET.Feature

    So Change the INVOKE statement and it should work now

    And IT will be good for you (if you want to be able to solve things like this on your own) to learn about structrues and the use of them...

    1 reply

    talofer99
    Inspiring
    May 2, 2011

    example for you to work with :

    cfajaximport>

    <cfif isdefined('url.search')>
    <cfdump var="#url#">
    <cfabort>
    </cfif>


    <cfform>
    <cfinput type="text" name="search">
    <cfinput type="checkbox" name="checkbox1" checked="TRUE" value="11">
    </cfform>

    <cfdiv bind="url:index.cfm?search={search@keyup}&checked={checkbox1.checked@click}&checkboxvalue={checkbox1@click}">>

    </cfdiv

    This will load the index.cfm every time u :

    Check/un check the checkbox, and will post the TRUE/FALSE state fo the checkbox - checked={checkbox1.checked@click} // checkboxvalue={checkbox1@click

    Type in any text in the text box.

    Hope this helps.

    May 3, 2011

    It is very good example for me ! Thank a lot !

    I am trying with it ! thank thank