Solved

cfselect bind to another cfselect

Posted on 2012-12-20
6
355 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
  • 3
  • 3
6 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

17 Experts available now in Live!

Get 1:1 Help Now