Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

ColdFusion Ajax Search Form ? Or Seach Filter ?

Guest
Apr 29, 2011 Apr 29, 2011

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?

6.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , May 04, 2011 May 04, 2011

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 thin

...
Translate
Participant ,
May 01, 2011 May 01, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 03, 2011 May 03, 2011

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

I am trying with it ! thank thank

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 03, 2011 May 03, 2011

Can i ask another question about the database SELECT ?

the database must SELECT all in 1 cffuntion ?

all can be sepeaate those database SELECT ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 03, 2011 May 03, 2011

I'm not sure I understand your Q' .. can you ask with an example ... it will be easier for me to help out ..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 03, 2011 May 03, 2011

If accoding to your example, i don't want the checbox with checked, but i want their default = "". Can set the cfargument default="" ? or use <cfparam> ?

Let say this is my component.

<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.Feature_ID#")

         </cfif>

         GROUP BY r.Name

         </cfquery>

        <cfreturn CheckBox>

         </cffunction>

</cfcomponent>

Ok. above is my component, but the content only for checkbox,

if later i will include some input with text or selection ,

there will more table to add on with different input,

my question is i need to set all SELECT database in same <cfquery> or separate them ?

BTW, my component cant get the result,

the result is always default "",

my idea result is will be change when checkbox change.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 03, 2011 May 03, 2011

1. Check box CHECKED has 2 optional (only) values : TRUE/FALSE.

2. I'm not sure how u want to pass Feature_ID into the Function, where is that value comeing from ? and what type is it ? INT/CHAR ?

3. about adding more caluses to the WHERE .. no problem as long as you can apply that logic, Ie get all the options under one query. its beter to maintain ONE READ from each table in the database, if not every time u make a change in the db u need to make a chnage in more then one function.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 03, 2011 May 03, 2011

I have try a simple way with the checkbox without ajax.

I set a input submit button and when click it the submit will send to result page, it is working with those code almost same with my curreny component code.

Just face problem when wanna make it as ajax.

The feature_ID from table features, and it type is INT.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 03, 2011 May 03, 2011

post the code fo were the CFFORM is ...

maybe then I will get what you are tryign to do and why its failing ...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 03, 2011 May 03, 2011

talofer99 , i am really appreciate for your patient, thank you !

i post the code that working well without ajax.

<cfquery datasource="Reservation" name="Features">

SELECT Feature_ID, Feature

FROM Features

</cfquery>

<cfform action="Search_Features_Result.cfm">

Feature:

<cfoutput query="Features">

<input type="checkbox"

   name="Feature_ID"

   value="#Feature_ID#">#Feature# <br />

</cfoutput>

</cfform>

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

<cfparam name="FORM.Feature_ID" default="">

<cfquery name="Restaurants" datasource="Reservation">

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 FORM.Feature_ID IS NOT "">

AND f.Feature_ID IN (#FORM.Feature_ID#)

</cfif>

GROUP BY r.Name

</cfquery>

<cfoutput query="Restaurants">

#Restaurant_ID#  </br>

#Name#

<

</cfoutput>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 03, 2011 May 03, 2011

ok can u now post the DIV BIND u created ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 03, 2011 May 03, 2011

<cfinvoke component="test2"

  method="getFeatures"

  returnvariable="Features">

<cfoutput query="Features">

         <input type="checkbox"

                   name="Feature_ID"

                   value="#Feature_ID#"

                   >#Feature# <br />

</cfoutput>

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

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

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

<cfinvoke component="test2"

  method="sendFeatures" search="#url.checkboxvalue#" returnvariable="results">

<cfoutput query="results">

     #Restaurant_ID#

     #Name#

</cfoutput>

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

this is 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.Feature_ID#")

     </cfif>

     GROUP BY r.Name

     </cfquery>

     <cfreturn CheckBox>

</cffunction>

</cfcomponent>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 03, 2011 May 03, 2011

Your problem is in the INVOKE

<cfinvoke component="test2"

  method="sendFeatures" search="#url.checkboxvalue#" returnvariable="results">

Search IS NOT ANY OF THE CFC ARGUMNETS ...

So you need to pass the Vlue in ..

useing :

argumentCollection = "argument collection"

So it needs to look like this :

<cfset args = structnew()>

<cfset args.Feature_ID = url.checkboxvalue>

<cfinvoke component="test2"

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

To match the

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

Next time CFDUMP the ARGUMNETS inside the CFC ,,, this wil lallwo you to "see" what goes into the CFC ....

Have fun

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 03, 2011 May 03, 2011

Thank talofer99.

i have modify result page to

<cfset args = structnew()>

<cfset args.Feature_ID = url.checkboxvalue>

<cfinvoke component="test2"

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

then i get the error

Called from C:\wamp\www\Test\test2a.cfm: line 5
Called from C:\wamp\www\Test\test2.cfc: line 27
Called from C:\wamp\www\Test\test2a.cfm: line 5
25 :           where b.Feature_ID = f.Feature_ID AND b.Restaurant_ID = r.Restaurant_ID 
26 :           <cfif #ARGUMENTS.Feature_ID# IS NOT "">
27 :           AND f.Feature_ID IN (#ARGUMENTS.Feature_ID#")

i have try to change the arguments became args have to same error.

by the way, i am asking a silly question, sorry, how to CFDUMP in arguments ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 03, 2011 May 03, 2011

remove the DBLQUOTE in the end of this

AND f.Feature_ID IN (#ARGUMENTS.Feature_ID#") <--- this dbl quote ... This iswhy  Iasked u what type of FIELD is the id .. I noticed the unneeded " before ..

and to dump the variables

<cfdump var="#arguments#">

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 04, 2011 May 04, 2011

Ops sorry, i did not notice the double quote. it is my fault.

It is working without error, but the result would not change any more, keep maintain with default.

I try to tick few of the checkbox, it only change the value in the column of the search.

Column feature_ID only with empty string.

struct
FEATURE_ID[empty string]
SEARCH
struct
FEATURE_ID4,5

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 04, 2011 May 04, 2011

IS this the DUMP of the ARGUMNETS struct insdie the CFC ?

If so, somthign is still not ok ... can u post the code of the page that populate the div output ?

Do you understand the structure output ?

and what is not ok ?

Notice that the FEATURE_ID is EMPTY

and then you have SEARCH STRUCT that contain this : FEATURE_ID ...

So once you will show how you cretae the structure I can tell you where its going wroung

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 04, 2011 May 04, 2011

so in thoury if it is the dump of the ARGUMENTS colletion inside the cfc

if yo uto do this :

<cfif #ARGUMENTS.Feature_ID# IS NOT "">
27 :           AND f.Feature_ID IN (#ARGUMENTS.Search.Feature_ID#)

It should work ..

but its better to pass the info in currectly .... then to "fix" it inside the cfc

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 04, 2011 May 04, 2011

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 04, 2011 May 04, 2011

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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 04, 2011 May 04, 2011

OMG !@! It is working pretty well now ! !!

Sorry it is my mistake again , feel so sorry to u.

Yup, i will continue improve my coldfusion !

This is one of my school assignment , so abit rushing with it !

Really wanna say thoudsand thank to you !! !

Really nice to meet you

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 04, 2011 May 04, 2011

You welcom ...

enjoy CF its a very powerfull platform ...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 04, 2011 May 04, 2011

Yeah , it is powerfull platform.

I have a long journey for learning .

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 05, 2011 May 05, 2011

Can i continue ask some question ? But u have the right to ignore.

If i wanna add another checkbox but different value and table.

Is it i continue the cfdiv became ?

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

then add one more

<cfset args.Price = url.checkboxvalue>

But i think i can't add 1 more

<cfargument name="Price _ID" type="any"  default="">

in the component content.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 05, 2011 May 05, 2011

You are makeing mess of things since you don;t spend the time learning the basics of STRUCTURES ....

You can do this :

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

SHOULD BE

<cfdiv bind="url:Search_Features_Result.cfm?checkboxvalue={Feature_ID@click} &checkboxvalue2={Price_ID@click}">

this 

<cfset args.Price = url.checkboxvalue>

Should be

<cfset args.Price = url.checkboxvalue2>

AND THIS  CAN NOT BE ... since one line above you called it "Price"

<cfargument name="Price _ID" type="any"  default=""> (also notice the unneeded space)

So it can be

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

OR change the

<cfset args.Price_Id  = url.checkboxvalue2>

Names in structure must match .....

And I will go ahead and chaneg the PARAM in the URL to

<cfdiv bind="url:Search_Features_Result.cfm?Feature_ID={Feature_ID@click} &Price_ID={Price_ID@click}">

and then u can invoke the CFC using URL as the ARGUMENTCOLLECTION ... (instead of haveing to buield one ... with <cfset args = structnew()>)

Please refer to the manual and the endless samples on the web for things like that ....

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources