Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with cascading dropdown boxes 1

Status
Not open for further replies.

dinger2121

Programmer
Sep 11, 2007
439
0
0
US
Hello,
I am attempting to create a set of cascading dropdown boxes using a component. I have the following code in my component.cfc -
Code:
<cfcomponent output="false">
<!--- Code for creating cascading drop down list for categories  ---> 
    <cfset THIS.dsn="inventory">

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

        <!--- Get data --->
        <cfquery name="data" datasource="#THIS.dsn#">
        SELECT id,name 
		FROM category 
		GROUP BY name
		ORDER BY name
        </cfquery>

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

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

    <!--- Get subcategory by category --->
    <cffunction name="getSubCategory" 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="#THIS.dsn#">
        SELECT id,subcategory FROM category WHERE id = #ARGUMENTS.categoryid# ORDER BY artname
        </cfquery>
    
        <!--- Convert results to array --->
        <cfloop index="i" from="1" to="#data.RecordCount#">
            <cfset result[i][1]=data.id[i]>
            <cfset result[i][2]=data.subcategory[i]>
        </cfloop>

        <!--- And return it --->
        <cfreturn result>
    </cffunction>
<!--- END Code for creating cascading drop down list for categories  ---> 
</cfcomponent>

And here are the boxes in the cfm file -
Code:
<tr>
	<td align="right" nowrap><font size="-1"><B>Category:</B></font></td>
	<td>
		<cfselect name="categoryid" bind="cfc:category.getCategory()" bindonload="true">
			<option name="0">--Select Category--</option>
		</cfselect>
	</td>
  </tr>
  <tr>
	<td align="right" nowrap><font size="-1"><B>Sub-Category:</B></font></td>
	<td>
		<cfselect name="subcategoryid" bind="cfc:category.getSubCategory({categoryid})">
			<option name="0">--Select Sub-Category--</option>
		</cfselect>
	</td>
  </tr>

The problem that I am having is that the initial category drop down is not populating at all. I am not getting any error messages, so I have no idea what is missing. I know it is successfully hitting the functions in the cfc file because if I erroneously modify my query, it will produce the expected errors.

can anyone make a recommendation?

Thanks

carl
MCSD, MCTS:MOSS
 
Run the functions manually with cfinvoke and dump the results. Do they it work?

Also, turn on ajax debugging. Enable the setting in the CF Administrator. Then add "?cfdebug" to the page url to view the ajax log.



----------------------------------
 
I have the function returning an array. I am new to CF, and I tried cfinvoke, but I don't know how to dump the results. When I ran the cfinvoke, I was using the following -

Code:
<CFINVOKE COMPONENT="category" METHOD="getCategory" RETURNVARIABLE="getCategories" />

but that was giving me an error regarding simple types b/c I am returning an array and not something like a string, int, etc.

how do I dump the results? I am going to try the ajax debugging and see if that reveals anything.

carl
MCSD, MCTS:MOSS
 
I changed my function to return a query instead of an array.
I then added the following code -

Code:
<CFINVOKE COMPONENT="category" METHOD="getCategory" RETURNVARIABLE="getCategories" />
<br/><cfdump var="#getCategories#"><br/>

and the correct data was being dumped.
That leads me to believe that there is a problem with my binding.

carl
MCSD, MCTS:MOSS
 
I do not see any obvious problems with the original. (What did the ajax logger report?) But if you change the function to return a query, then you will probably need to modify the cfselects. So CF knows which columns to use for the option value and text

Code:
<cfselect name="categoryid"
      value="ID" 
      display="Name"
      bind="cfc:category.getCategory()"
      bindOnLoad="true"
   />


----------------------------------
 
Yes, I did modify the cfselect, but still nothing.
I am not able to see anything in the ajax logger - it doesn't seem to be working as expected. I enabled it in CF Administrator and added ?cfdebug to the URL, but nothing.

carl
MCSD, MCTS:MOSS
 
I am able to use firebug in firefox to determine that the expected data is coming back. I just cannot get the query to bind to the cfselect....

carl
MCSD, MCTS:MOSS
 
I am able to use firebug in firefox to determine that the expected data is coming back. I just cannot get the query to bind to the cfselect....

Does the cfselect have to reside within a cfoutput and cfform tag?
it currently is within both of those tags - I don't know if that will make a difference.

carl
MCSD, MCTS:MOSS
 
CFFORM, yes. Just for grins, try removing the blank <option>. It will disappear on bind anyway.

Have you successfully used _any_ cf functionality, like cfform validation, cfcharts, etcetera?

----------------------------------
 
I've used cfif, cfset, cfloop - these all work fine.
unfortunately, this is an app that I inherited, so there is alot going on besides just this.

I will try these out.

Thanks for all the help.

carl
MCSD, MCTS:MOSS
 
No, I meant there are certain tags that require files in the /CFIDE directory to work properly. For example cfform, cfchart, etc.

Do you get a javascript alert if you run the following code?
Code:
<cfform>
	<cfinput type="text" name="something" required="true" message="This field is required!">
	<cfinput type="submit" name="submitBtn">
</cfform>

so there is alot going on besides just this

Then you should isolate the code. Create a simple test page, with just the cfform and cfselect lists. If the code works there, the problem is something else on your main page.

----------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top