Solved

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

Posted on 2010-08-20
6
591 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

 

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

710 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