Solved

Coldfusion dependent dropdown and url values.

Posted on 2009-04-05
10
413 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

Question has a verified solution.

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

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…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

12 Experts available now in Live!

Get 1:1 Help Now