Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Coldfusion dependent dropdown and url values.

Posted on 2009-04-05
10
415 Views
Last Modified: 2013-12-24
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
Comment
Question by:Panos
  • 5
  • 5
10 Comments
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24071122
0
 
LVL 2

Author Comment

by:Panos
ID: 24071139
Hi azadi
Can you make the changes to my code?
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24071212
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 2

Author Comment

by:Panos
ID: 24071233
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
 
LVL 27

Accepted Solution

by:
azadisaryev earned 500 total points
ID: 24071445
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
 
LVL 2

Author Comment

by:Panos
ID: 24071576
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
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24071589
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
 
LVL 2

Author Comment

by:Panos
ID: 24071628
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
 
LVL 2

Author Closing Comment

by:Panos
ID: 31566731
Thank again azadi for your help
regards
panos
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24071634
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

839 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