Solved

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

Posted on 2010-08-20
6
588 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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 

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

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.

Question has a verified solution.

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

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…

828 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