Solved

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

Posted on 2010-08-20
6
583 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now