Skip to main content
Known Participant
May 11, 2010
Question

problem with a bound cfselect using the selected feature.

  • May 11, 2010
  • 1 reply
  • 1644 views

I'm trying to get my bound cfselects to know if a record

was pulled up, and a selection was made, the cfselect shows it. If your adding a new

record, it doesn't matter. I get it to work without the bind, but I think this is a little different and not workin

g the way I need it to. Can anyone help me? I'll put in my 2 selects.. if you need more code, I can provide it. I'll als

o add the query that is called up for the page, the selects are populated by the cfc file, so maybe I'm going abo

ut this in the wrong direction?

query:

<cfquery name="categRec" datasource="#APPLICATION.dataSource#">
SELECT c.CategoryID, c.CatName AS cat_name, p.MerchName, p.MerchDescription, p.MerchPrice, p.MYFile, p.ProNumber, p.merchID, p.subID
FROM merchCategory AS c
INNER JOIN Merchandise AS p ON c.CategoryID = p.CategoryID
WHERE p.merchID = <cfqueryparam value="#URL.ID#" cfsqltype="cf_sql_integer">
AND c.CategoryID = p.CategoryID
</cfquery>

My Selects:

<cfselect
                bind="cfc:art.getMedia()" enabled="No"
                bindonload="true" name="CategoryID" multiple="no" selected="#url.ID#" />

<cfselect
                bind="cfc:art.getArt({CategoryID})" enabled="No" name="subID" multiple="no" selected="#url.ID#" />

Can anyone help me out? I can make my .cfc querys or file available if needed.

    This topic has been closed for replies.

    1 reply

    Inspiring
    May 11, 2010

    AFAIK the "selected" attribute does not work prior to CF9. If you are using CF8 there are various work arounds (on the blogs of Raymond Camden, et al). Just do a search on: cfselect bind selected

    http://www.coldfusionjedi.com/index.cfm/2007/8/7/Selecting-default-items-using-ColdFusion-8s-AJAX-Controls

    ...etcetera...

    Known Participant
    May 11, 2010

    thank you, I found an article, it looks like i need to add a selected value into the bind code. I am trying to do it now, but not doing very well. Can you help me add it in? here is what I did so far, and my error. Obviously from the error, I'm after the wrong variable, and probably added it incorrectly.

    Error:


    The ID method was not found.

    Either there are no methods with the specified method name and argument types, or the ID method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that matched the provided arguments. If this is a Java object and you verified that the method exists, you may need to use the javacast function to reduce ambiguity.
    The error occurred in C:\Websites\187914kg3\admin\cms\merchant\merchEdit.cfm: line 113
    111 :     <tr>
    112 :         <td><span style="margin-right:10px; font-family:Verdana, Geneva, sans-serif; font-size: 14px; color:##000">Select Category:</span></td>
    113 :         <td><cfselect bind="cfc:art.getMedia(),#url.ID()#" enabled="No"
    114 :                 bindonload="true" value="CategoryID" name="CategoryID" multiple="no" display="cat_name" /></td>
    115 :     </tr>
    


    Selects:
    <cfselect bind="cfc:art.getMedia(),#url.ID()#" enabled="No"
                    bindonload="true" value="CategoryID" name="CategoryID" multiple="no" display="cat_name" />

    <cfselect
                    bind="cfc:art.getArt({CategoryID})" enabled="No" name="subID" multiple="no" selected="#url.ID#" />

    My CFC file;

    <cfcomponent output="false">

        <!--- Get array of media types --->
        <cffunction name="getMedia" access="remote" returnType="array">
            <!--- Define variables --->
            <cfset var data="">
            <cfset var result=ArrayNew(2)>
            <cfset var i=0>

            <!--- Get data --->
            <cfquery name="data" datasource="#APPLICATION.dataSource#">
            SELECT CategoryID, CatName
            FROM merchCategory
            ORDER BY CatName
            </cfquery>

            <!--- Convert results to array --->
            <cfloop index="i" from="1" to="#data.RecordCount#">
                <cfset result[1]=data.CategoryID>
                <cfset result[2]=data.CatName>
            </cfloop>

            <!--- And return it --->
            <cfreturn result>
        </cffunction>

        <!--- Get art by media type --->
        <cffunction name="getArt" access="remote" returnType="array">
            <cfargument name="CategoryID" type="numeric" required="true">

            <!--- Define variables --->
            <cfset var data="">
            <cfset var result=ArrayNew(2)>
            <cfset var i=0>

            <!--- Get data --->
            <cfquery name="data" datasource="#APPLICATION.dataSource#">
            SELECT subID, subName, CategoryID
            FROM merchSubCat
            WHERE CategoryID = #ARGUMENTS.CategoryID#
            ORDER BY subName
            </cfquery>
       
            <!--- Convert results to array --->
            <cfloop index="i" from="1" to="#data.RecordCount#">
                <cfset result[1]=data.subID>
                <cfset result[2]=data.subName>
            </cfloop>

            <!--- And return it --->
            <cfreturn result>
        </cffunction>

    </cfcomponent>

    From what I'm reading, it says, both binds need to have the variables in them if it is selected. I could be wrong..

    I'm new to binds.

    Inspiring
    May 11, 2010

    You might want to look at the article again.  I do not see where you added the code mentioned in the entry. The new code is mainly javascript, called with cfajaxproxy. The basic cfselect code remains the same. 

    Message was edited by: -==cfSearching==-

    Message was edited by: -==cfSearching==-