Solved

Coldfusion dependent dropdown and url values.

Posted on 2009-04-05
10
411 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
 
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now