Solved

Coldfusion dependent dropdown and url values.

Posted on 2009-04-05
10
417 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
[X]
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
  • 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

749 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