Solved

cfselect bind to another cfselect

Posted on 2012-12-20
6
387 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

685 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