Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I bind a query to <cfselect without using XML?

Posted on 2010-08-20
6
Medium Priority
?
595 Views
Last Modified: 2013-12-24
Hello,

I have a <cfselect tag that is populated by a query.  Right now it has a list of states that I maintain in a database table.

What I would like to do is bind another <cfselect tag to display cities based on the state selection... I have seen many examples using XML (for example, in Adobe's docs.) but I would like to avoid this because I do not want to maintain an XML file for form data and another table for other application processes......

Please let me know if this is possible.

Thank you very much in advance!!!!!!!
0
Comment
Question by:stracqan
6 Comments
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 33490635
hi.....

you can do so by AJAX/JAVASCRIPT...........
if u want,i will give you more info on.........
0
 
LVL 1

Expert Comment

by:mugsinc
ID: 33490915
Use jquery. There are loads of examples if you google it.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 33494802
Here an example:
<cfset states=QueryNew("") >
<cfset QueryAddColumn(states,"country",ListToArray("Canada,Canada,Canada,Canada,Canada,Canada,Mexico,Mexico,Mexico,Mexico,Mexico,Mexico,Unites Sates,Unites Sates,Unites Sates,Unites Sates,Unites Sates,Unites Sates")) >
<cfset QueryAddColumn(states,"state",ListToArray("Alberta,Alberta,British Columbia,British Columbia,Ontario,Ontario,Baja California,Baja California,Chihuahua,Chihuahua,Jalisco,Jalisco,California,California,Florida,Florida,New York,New York")) >
<cfset QueryAddColumn(states,"city",ListToArray("Edmonton,Calgary,Victoria,Vancouver,Toronto,Hamilton,Tijauna,Mexicali,Ciudad Juárez,Chihuahua,Guadalajara,Chapala,Los Angeles,San Francisco,Miami,Orlando,Buffalo,new York")) >

<cfquery name="qryCountry" dbtype="query" >
  SELECT DISTINCT country FROM states
         ORDER BY country
</cfquery>

<cfform name="myform" preservedata >

<cfselect name="selCountry" query="qryCountry" value="country" queryPosition="below" onChange="this.form.submit()" >
 <option value="">select State</option>
</cfselect>

<cfif isDefined("FORM.selCountry") AND FORM.selCountry GT "" >
  <cfquery name="qryState" dbtype="query" >
    SELECT DISTINCT state FROM states
           WHERE country='#FORM.selCountry#'
           ORDER BY state
  </cfquery>
  <cfselect name="selState" query="qryState" value="state" queryPosition="below" onChange="this.form.submit()">
    <option value="">select State</option>
  </cfselect>
</cfif>

<cfif isDefined("FORM.selState") AND FORM.selState GT "" >
  <cfquery name="qryCity" dbtype="query" >
    SELECT city FROM states
           WHERE state='#FORM.selState#'
           ORDER BY city
  </cfquery>
  <cfselect name="selCity" query="qryCity" value="city" >
  </cfselect>
  <cfinput type="submit" name="formSubmit" value="Select" >
</cfif>

</cfform>

Open in new window

0
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 

Author Comment

by:stracqan
ID: 33507932
Hello,

Thank you for your responces.  @Zvonko thank you for your post, but I would like to have the second select box populated without submitting the form data.

@mugsinc and @Brichsoft thank you for your responces as well.  Could you point me to an example using javascript or jquery?

Thanks again!!!!!!!!!!!!
0
 
LVL 19

Accepted Solution

by:
Bhavesh Shah earned 1500 total points
ID: 33509774

Hi,

Right now I'm giving you ready made example of ajax code.
please look at it and feel free if you have any doubt regarding that.

http://www.fusionauthority.com/techniques/4593-using-ajax-with-coldfusion-part-i.htm
0
 

Author Closing Comment

by:stracqan
ID: 33518398
Thanks!
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question