Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

cfselect bind to another cfselect

Posted on 2012-12-20
6
Medium Priority
?
404 Views
Last Modified: 2012-12-27
Hi all, need help with a cfselect bind.

I'm using this as a tutorial: http://tutorial544.easycfm.com/

Here's my page:  http://pcgrecords.com/vol/test.cfm

The first select, year, isn't bound, so ignore that.  But the rest of the cfselects on that page have a bind to the one before it.  (So the 'makes' one populates the 'models', and etc.)

Everything is ok until I get to the last one.  What I really want, is for the last cfselect, Select an OE, to be bound not just to the engine cfselect before it, but to the select model field as well.

Please help!

Here's the relevant code on the page, and the cfc is attached in a txt file.

   <tr>
         <td>Select Model:</td>
         <td><cfselect name="model" bindOnLoad="Yes" bind="cfc:data.getmodel({makes})" />
         </td>
</tr>
 <tr>
         <td>Select Engine:</td>
         <td><cfselect name="engine" bindOnLoad="Yes" bind="cfc:data.getengine({model})" />
         </td>
</tr>
<tr>
         <td>Select OE:</td>
         <td><cfselect name="OE"  bind="cfc:data.getOE({engine})" />
         </td>
</tr>

---------
0
Comment
Question by:Rush_2112
[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
  • 3
  • 3
6 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 38711378
Did you forget to attach the cfc/txt file? I don't see it.

Quick aside, the "Engine" list seems to repeat the same value multiple times. Not sure if that's what you want?

      > What I really want, is for the last cfselect, Select an OE, to be
      > bound not just to the engine cfselect before it, but to the select
      > model field as well.

You can bind to multiple fields.  Just add the second field to your bind

    <cfselect name="OE"  bind="cfc:data.getOE({model}, {engine})" />

... and as another argument to your cffunction/query.  (I can't be more specific without


      <cffunction name="getOE" ....>
               <cfargument name="model" ....>
               <cfargument name="engine" ....>
                ...

                <cfquery>
                     SELECT  SomeColumns
                     FROM    YourTable
                     WHERE   ModelColumn = <cfqueryparam value="#argument.model#" ...>
                     AND       EngineColumn = <cfqueryparam value="#argument.engine#" ...>
                </cfquery>

                ....
      </cffunction>
0
 
LVL 1

Author Comment

by:Rush_2112
ID: 38713520
Sorry, guess it didn't upload... its there now.   Thanks for helping.  

I was following a tutorial so I don't know what that line does or why it's duplicated.  Does the cfc help?
cfc.txt
0
 
LVL 1

Author Closing Comment

by:Rush_2112
ID: 38713851
Thanks, even without the rest of the code, you got it!
0
How to Create Failover DNS Record Sets in Route 53

Route 53 has the ability to easily configure DNS record sets specifically for failover scenarios. These failover record sets can be configured to failover to full-blown deployments in other regions or to a static HTML page that informs your customers of the issue.

 
LVL 52

Expert Comment

by:_agx_
ID: 38713989
Looks like it's just duplicated in the data ie db table. So just add a DISTINCT in the query. That'll take care of it.

Btw, the tutorial code is a little outdated.  As of CF8.0.1 you can bind directly to a query, so there's no need to build a separate array.  Just return the query from the function.  Then specify the "value" and "display" column in your cfselect.  

It's also a good practice to 1) always VAR scope variables (prevent hard to trace threading problems) and 2) use cfqueryparam (sql injection) and 3) scope all variables

Here's how I'd rewrite it.  Unfortunately I can't test it out right now, watch out for typos.

FORM

<tr>
         <td>Select Model:</td>
         <td><cfselect name="model" bindOnLoad="Yes" bind="cfc:data.getmodel({makes})"
                 display="model" value="model" />
         </td>
</tr>
 <tr>
         <td>Select Engine:</td>
         <td><cfselect name="engine" bindOnLoad="Yes" bind="cfc:data.getengine({model})"
                 display="engine" value="engine" />
         </td>
</tr>
<tr>
         <td>Select OE:</td>
         <td><cfselect name="OE"  bind="cfc:data.getOE({model}, {engine})" 
                 display="OE" value="OE" />
         </td>
</tr>

Open in new window


CFC
<cfcomponent output="false">
    <cfset variables.dsn = "Volusion">

    <cffunction name="getmakes" access="remote" returntype="query">
        <cfset var getData = "">

        <cfquery name="getData" datasource="#variables.dsn#"> 
            SELECT DISTINCT make FROM ECM
            ORDER BY make
        </cfquery>

        <cfreturn getData />
    </cffunction>
    
    <cffunction name="getmodel" access="remote" returntype="query">
        <cfargument name="make" type="string" required="true">
    
        <cfset var getData = "">
        <cfquery name="getData" datasource="#variables.dsn#">
            SELECT DISTINCT model FROM ECM
            WHERE make = <cfqueryparam value="#arguments.make#" cfsqltype="cf_sql_varchar">
            ORDER BY model
        </cfquery>

        <cfreturn getData />
    </cffunction>
    
    <cffunction name="getengine" access="remote" returntype="query">
        <cfargument name="model" type="string" required="true">
    
        <cfset var getData = "">
        <cfquery name="getData" datasource="#variables.dsn#">
            SELECT  engine FROM ECM
            WHERE model = <cfqueryparam value="#arguments.model#" cfsqltype="cf_sql_varchar">
            ORDER BY model
        </cfquery>

        <cfreturn getData />
    </cffunction>
    
    <cffunction name="getOE" access="remote" returntype="query">
        <cfargument name="model" type="string" required="true">
        <cfargument name="engine" type="string" required="true">
    
        <cfset var getData = "">
        <cfquery name="getData" datasource="#variables.dsn#">
            SELECT OE FROM ECM
            WHERE model = <cfqueryparam value="#arguments.model#" cfsqltype="cf_sql_varchar">
            AND   engine = <cfqueryparam value="#arguments.engine#" cfsqltype="cf_sql_varchar">
            ORDER BY OE
        </cfquery>

        <cfreturn getData />
    </cffunction>
    
</cfcomponent>

Open in new window

0
 
LVL 52

Expert Comment

by:_agx_
ID: 38720851
> Thanks, even without the rest of the code, you got it!

Oops.. sorry I missed your last comment before posting :) (But having a fuller example for the archives couldn't hurt) Anyway, glad I could help.
0
 
LVL 1

Author Comment

by:Rush_2112
ID: 38723886
thanks for the update!  I'll try that out too!
0

Featured Post

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

Question has a verified solution.

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

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

704 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