Skip to main content
Inspiring
May 15, 2008
Question

problem in drop down

  • May 15, 2008
  • 3 replies
  • 510 views
I am trying to do a query which will be based as :

schoolID s the PK
catID as reference to schools table.
CATid of categories table

Now i am trying to do like this:

i want i should select the category from drop, menu and name should appear in the dependent dropdown.

but due to some mine mistake i am in problem?

here is my complete code,:

<SCRIPT type="text/javascript" language="JavaScript1.2">
var arrLocations = new Array();
<cfoutput query="alldropdowns">
arrLocations[#alldropdowns.CurrentRow# - 1] =
new property(#alldropdowns.schoolid#,#alldropdowns.catid#,"#alldropdowns.campcategory#");
</cfoutput>
function property(sub1,ptype_Id,property_type_name){
this.sub1 = catid;
this.ptype_Id = catid;
this.property_type_name = campcategory;
}
function onChangeProperty(propertySelect,thisForm){
thisForm.elements["property"].length = 0;
for (var iii = 0; iii < arrLocations.length; iii++) {
if (propertySelect.value == arrLocations[iii].sub1) {
var newOption = new Option(arrLocations[iii].property_type_name,arrLocations[iii].ptype_Id);
thisForm.elements["property"].options[thisForm.elements["property"].length] = newOption;
}
}
if (thisForm.elements["property"].length == 0){
if (thisForm.elements['subdivision'].value == -1){
var newOption = new Option("Select Subdivision First!",-1);
}
else{
var newOption = new Option("N/A",-1);
}
thisForm.elements["property"].options[0] = newOption;
}
thisForm.elements["property"].options[0].selected = true;
}
</SCRIPT>


<tr>
<td class="b_settings"><p>Subdivision:</p></td>
<td><cfselect name="subdivision" size="1" class="b_settings"
onChange="onChangeProperty(this, this.form);" required="yes">
<option value="-1" selected="selected">Select Subdivision...</option>
<cfoutput query="Newcategory">
<option value="#catid#">#campcategory#</option>
</cfoutput> </cfselect>
<span class="startcolor">*</span> </td>
</tr>
<tr>
<td class="b_settings"><p>Property Type:</p></td>
<td><cfselect name="property" size="1" class="b_settings" required="yes">
<option value="-1" selected="selected">Select a Subdivision First!</option>
</cfselect>
<span class="startcolor">*</span> </td>
</tr>

The query which is deriving all these are:

<cffunction access="public" returntype="query" name="Combined">
<cfquery name="getLocal" datasource="#request.dsn#">
SELECT school_camps.catID, school_camps.schoolID, school_camps.campName, tblcategories.catID,
tblcategories.campcategory
FROM school_camps INNER JOIN tblcategories ON school_camps.catID = tblcategories.catID
ORDER BY campName asc
</cfquery>
<cfreturn getLocal>
</cffunction>

calling the CFC as:

<cfinvoke
component="EcoLife.admin.CFC.users"
method="Combined"
returnvariable="allDropdowns"/>
<cfinvoke
component="EcoLife.admin.CFC.users"
method="getCategory"
returnvariable="Newcategory"/>


Can anybody guide me please, what doing wrong here?

This topic has been closed for replies.

3 replies

Inspiring
May 16, 2008
back to basics. Cold Fusion Code runs on the server. The user does stuff on the client. Processing that is either a page request, javascript, or actionscript.

Those cfc's are Cold Fusion. They run on the server. Your 2nd function has a required numerical argument, and I don't see where you are passing that argument to the function.

I think the version in your 1st post is the one with the greatest potential.
Inspiring
May 16, 2008
One difference between my approach and yours is that I bring in all possible values for the 2nd select when I load the page. You appear to doing something else.
Inspiring
May 16, 2008
okay lets make it easy way?

i changed a bit and tried like it to bnd with the values as:

<cffunction name="getTheCats" access="remote" returnType="query">
<cfquery name="data" datasource="#request.dsn#">
<cfset var data="">
SELECT catid, campcategory
FROM tblcategories
ORDER BY catID
</cfquery>

<cfreturn data>
</cffunction>

<!--- Get art by media type --->
<cffunction name="getCampCategory" access="remote" returnType="query">
<cfargument name="catid" type="numeric" required="true">
<cfset var data="">

<cfquery name="data" datasource="#request.dsn#">
SELECT schoolid, CampName
FROM school_camps
WHERE catid = <cfqueryparam cfsqltype="cf_sql_numeric" value="#Trim(ARGUMENTS.catid)#">
ORDER BY artname
</cfquery>
<cfreturn data>
</cffunction>
<tr>
<td>Select Category Type:</td>
<td><cfselect name="catid"
bind="cfc:art.getTheCats()" value="catid" display="campCategory" bindonload="true" /></td>
</tr>
<tr>
<td>Select Camp Name:</td>
<td><cfselect name="schoolid" value="schoolID" display="campName"
bind="cfc:art.getCampCategory({catid})" /></td>
</tr>

what here i am doing is calling the one category in the above select and show the name of the camp instead of ID in the select camp:

like table 1 is : catID, campcategory

table 2: catID {this is PK}, schooIid, catID{This is defined to calkl the values from table 1 in table 2}, campName.

i want to show as 1. select campcategory first, see if how many records are related to this.

Then in the 2 select show the CampName
under that category.

This was i am trying to do.

but not getting it?
\
Inspiring
May 16, 2008
I've only done this once, and it worked. This was my approach, http://www.pathcom.com/~bracuk/code/RelatedSelects.htm

Inspiring
May 16, 2008
Thanks Dan, I went through your code and it was good enough to get me understand what it was doing ?

Recenly i blogged Ben Forta's Blog and something similar to this drop down using Ajax, But i am running intop problem. The error i encountered has been encountered by many and it may be the cause something is propeling in this:

this is the Image i am having recieved as error:

[url=http://img234.imageshack.us/my.php?image=11188645oz7.gif][img=http://img234.imageshack.us/img234/2667/11188645oz7.th.gif][/url]

I am trying something like this:


<cffunction name="getTheCats" access="remote" returnType="query">
<!--- Define variables --->
<!---<cfset var data="">
<cfset var result=ArrayNew(2)>
<cfset var i=0>--->

<!--- Get data --->
<cfquery name="data" datasource="#request.dsn#">
SELECT catid, campcategory
FROM tblcategories
ORDER BY catID
</cfquery>

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

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

<!--- Get art by media type --->
<cffunction name="getCampCategory" access="remote" returnType="query">
<cfargument name="catid" type="numeric" required="true">

<!--- Define variables --->
<cfset var data="">
<!---<cfset var result=ArrayNew(2)>
<cfset var i=0>
--->
<!--- Get data --->
<cfquery name="data" datasource="#request.dsn#">
SELECT schoolid, CampName
FROM school_camps
WHERE catid = <cfqueryparam cfsqltype="cf_sql_numeric" value="#Trim(ARGUMENTS.catid)#">
ORDER BY artname
</cfquery>

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

<!--- And return it --->
<cfreturn data>
</cffunction>
<tr>
<td>Select Category Type:</td>
<td><cfselect name="catid"
bind="EcoLife.admin.cfc:art.getTheCats()" value="catid" display="campCategory" bindonload="true" /></td>
</tr>
<tr>
<td>Select Camp Name:</td>
<td><cfselect name="schoolid" value="schoolID" display="campName"
bind="EcoLife.admin.cfc:art.getCampCategory({catid})" /></td>
</tr>