Solved

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

Posted on 2010-08-20
6
584 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

939 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

9 Experts available now in Live!

Get 1:1 Help Now