• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 427
  • Last Modified:

Coldfusion dependent dropdown and url values.

Hello experts
I have a working code for two dependent select boxes. The problem i have is to get the value for the child field (S_Modell_ID)if the value is in Url .
Here is the script-cfm and cfc.
<cfinvoke component="test.com.getsearchmodell" method="getHersteller" returnvariable="qHersteller">
</cfinvoke>
<script type="text/javascript" src="../js/engine_micro.js"></script>
<script language="javascript" type="text/javascript">
function getModell(ID){
 //set the params required for your function
 if (isNaN(ID) || ID <= 0) ID = 0;
 var param = 'herstellerid='+ID;
 http('POST','../com/getsearchmodell.cfc?method=getMenu',showModell_response,param);
}
function showModell_response(obj){
 var mySelect = document.getElementById('S_Modell_ID');
 mySelect.options.length = 0;
 for (var c = 0; c < obj.modell_id.length; c++)
 {
  //note that jsmx calls always return lower case
  mySelect.options[c] = new Option(obj.modell_de[c] , obj.modell_id[c]);
 }      
}
</script>
 
 
 
<!--- CFM--->
<cfselect name="S_Hersteller_ID"  id="S_Hersteller_ID" onchange="getModell(this.value);">
            <option value="">All</option>
           <cfoutput query="qHersteller">
            <option value="#qHersteller.Hersteller_ID#" <cfif listFind(url.S_Hersteller_ID,qHersteller.Hersteller_id)> selected="selected"</cfif>>#qHersteller.Hersteller_Text#</option>
          </cfoutput>
       </cfselect>
       
       <cfselect name="S_Modell_ID" id="S_Modell_ID" class="selectleftbig">
<option value="" selected="selected">Select parent first</option>
</cfselect>
 
 
<!--- CFC --->
<cfcomponent output="false">
 <cffunction name="getHersteller" returntype="query">
  <cfset VAR qHersteller = "">
  <cfparam name="cookie.lang" default="de">
  <cfset vlangid = #cookie.lang# >
  <cfquery name="qHersteller" datasource="#request.dsn#">
  SELECT Hersteller_ID, Hersteller_Text
  FROM Hersteller
  WHERE Mobiles_Subs_ID = <cfqueryparam cfsqltype="cf_sql_numeric" value="1">
  OR (Hersteller_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="19999">
  AND LangID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#vLangID#">)	
  ORDER BY Hersteller_NR
  </cfquery>
  <cfreturn qhersteller>
</cffunction>
 
 <cffunction name="GetMenu" access="remote" output="false" returntype="query" hint="Returns a query of the submenu items based on the parent menu ID">
  <cfargument name="herstellerid" required="yes" type="numeric" hint="The parent ID of the items to return">
  <cfset var QGetMenu="">
  <cfquery datasource="#request.dsn#" name="QGetMenu">
  SELECT Modell_DE, Modell_ID
  FROM Modell_Auto_S
  WHERE Auto_ID = <cfqueryparam cfsqltype="cf_sql_numeric" value="#ARGUMENTS.herstellerid#">
  ORDER BY Modell_NR
  </cfquery>
  <cfreturn QGetMenu>
 </cffunction>
 </cfcomponent>

Open in new window

0
Panos
Asked:
Panos
  • 5
  • 5
1 Solution
 
azadisaryevCommented:
0
 
PanosAuthor Commented:
Hi azadi
Can you make the changes to my code?
0
 
azadisaryevCommented:
while i definitely could write the code for you, i do not think it is a good idea for a number of reasons...

a) it is not guaranteed to work since i do not really know the ins and outs of your application or how exactly you expect the code to work
b) the code you posted does not even attempt to implement the solution in Ray's blog post
c) me writing code for you will not teach you anything and will not help you become a better cf developer - next time you have the same or similar situation you will still not be able to solve it by yourself, or figure out what to change in the code to make it work in the new situation.

i strongly believe in "helping you help yourself" approach... so please do at least try to make it work, and if you get stuck i will absolutely do my best to help you solve a concrete code problem.

hope you do understand.

Azadi
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
PanosAuthor Commented:
The solution on the link you posted is using bind and bindonload.The cfc's are not there and if you remember i had in the past a problem to you the bind and bindoload functions
Well i will try to do my best..
0
 
azadisaryevCommented:
hmmm... you are right - your code is indeed is different: you are NOT using any cf8 ajax features in it! so Ray's solution is not needed for you.

all you need to do, is modify your showModell_response a bit and add an onLoad attrubute to the <body> tag of your page!

function showModell_response(obj){
 var modelid = <cfif isdefined('url.S_Modell_ID')><cfoutput>#url.S_Modell_ID#</cfoutput><cfelse>0</cfif>;
 var mySelect = document.getElementById('S_Modell_ID');
 mySelect.options.length = 0;
 for (var c = 0; c < obj.modell_id.length; c++)
 {
  //note that jsmx calls always return lower case
  mySelect.options[c] = new Option(obj.modell_de[c] , obj.modell_id[c]);
 if (obj.modell_id[c] == modelid) mySelect.options[c].selected = true;
 }      
}

<body onLoad="getModell(document.getElementById('S_Hersteller_ID').value);">

that's it!

Azadi
0
 
PanosAuthor Commented:
Hi Azadi
I get the parent but not the child value when the s_Modell_Id is not numeric.
It can be for example.
S_Hersteller_ID= 20
S_Modell_ID=Passat
S_Modell_Id is not numeric.
0
 
azadisaryevCommented:
that name -  S_Modell_ID - sure implies the value is numeric...

anyway, just a small change should be required in this case. try this changed line:

var modelid = <cfif isdefined('url.S_Modell_ID')><cfoutput>'#url.S_Modell_ID#'</cfoutput><cfelse>''</cfif>;

Azadi
0
 
PanosAuthor Commented:
You are right but i did begin building this column as numeric and at the end i changed the values without changing the name.
I should tell you that i did try to change all the code again to use the bind tags and the truth is that it easier that way but i have again problems with the default values.I will see later  how this works.
0
 
PanosAuthor Commented:
Thank again azadi for your help
regards
panos
0
 
azadisaryevCommented:
if you switch to using bindings in your cfselects, then to pre-select a value in them you will need to use Ray's solution.

Azadi
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now