Solved

Dynamic drop down based on another drop down using JavaScript and Coldfusion MX 7

Posted on 2008-10-01
2
876 Views
Last Modified: 2010-10-05
I was trying to populate a dropdown box based on the value from the first dropdown. I'm passing the value from the first dropdown to a javascript function and tried to invoke a CFC function that would populate values based upon the first dropdown. Attached is the code snippet. Any help would be appreciated.
<!--- CFC --->
 
<cffunction name="GetWQuotaUnits" access="public" returntype="any" output="true">
		<cfargument name="CycleDate" required="true">
		
		<cfquery name="qGetWQuotaUnits" datasource="#request.datasource#">
			select distinct units 
			from quotaplan_quotas
			where to_date('#arguments.CycleDate#','mm/dd/yyyy') between effdate and endeffdate
			and product = 'W'
			and recordtype = 'SERVICE'
			and quotaplan in 
    			(select quotaplan from compquotaplan 
   				where to_date('#arguments.CycleDate#','mm/dd/yyyy') between effdate and endeffdate
    			and compplan in 
        			(select compplan from compplans 
        			where to_date('#arguments.CycleDate#','mm/dd/yyyy') between effdate and endeffdate
        			and channel = 'Retail')
    				)
			order by 1
		</cfquery>
		
		<cfif qGetWQuotaUnits.RecordCount NEQ 0>
               <cfset rtnValue = qGetWQuotaUnits>
        <cfelse>
               <cfset rtnValue = "false">
        </cfif>
          
		<cfreturn rtnValue/>
	</cffunction>
	
	<!--- Get PrePaid Quota Units --->
	<cffunction name="GetPQuotaUnits" access="public" returntype="any" output="true">
		<cfargument name="CycleDate" required="true">
		<!--- <cfargument name="PrePaidUnits" required="true"> --->
		
		<cfquery name="qGetPQuotaUnits" datasource="#request.datasource#">
			select distinct units 
			from quotaplan_quotas
			where to_date('#arguments.CycleDate#','mm/dd/yyyy') between effdate and endeffdate
			and product = 'PREPAID'
			and recordtype = 'SERVICE'
			and quotaplan in
				(select distinct quotaplan 
				from quotaplan_quotas
				where to_date('#arguments.CycleDate#','mm/dd/yyyy') between effdate and endeffdate
				and units = '18'
				and product = 'W'
				and recordtype = 'SERVICE'
				and quotaplan in 
					(select quotaplan from compquotaplan 
					where to_date('#arguments.CycleDate#','mm/dd/yyyy') between effdate and endeffdate
					and compplan in 
						(select compplan from compplans 
						where to_date('#arguments.CycleDate#','mm/dd/yyyy') between effdate and endeffdate
						and channel = 'Retail')
					)
				)
			order by 1
		</cfquery>
		
		<cfif qGetPQuotaUnits.RecordCount NEQ 0>
               <cfset rtnValue = qGetPQuotaUnits>
        <cfelse>
               <cfset rtnValue = "false">
        </cfif>
          
		<cfreturn rtnValue/>
	</cffunction>
<!--- JavaScript --->
<script>
function PrePaidChoices(`){
									alert(selWVal);
									//build dropdown for PrePaid
									var ptr = document.StrMQuotaForm.SelPrepaid;
									// kill all current options
									//ptr.options.length = 0;
									//now loop through array creating options and adding
									var tmp = document.createElement("OPTION");
									tmp.value = "";
									txt = document.createTextNode("Select a PrePaid Value");
									tmp.appendChild(txt);
									ptr.appendChild(tmp);
									
									<!--- unitsArray = document.StrMQuotaForm.selPostPay.options[document.StrMQuotaForm.selPostPay.options.selectedIndex].value;
									alert(unitsArray); --->
									
									<cfoutput>
									
									<cfloop query="rtnGetPQuotaUnits">
										tmp = document.createElement("OPTION");
										tmp.value = "#units#";
										alert("units:"+#units#);
										<cfif isdefined('StrMQuotaForm.selPostPay')>
											if('#StrMQuotaForm.selPostPay#' == "#units#")
											{
												tmp.selected = true;
											}
										</cfif>
										txt = document.createTextNode("#units#");
										tmp.appendChild(txt);
										ptr.appendChild(tmp);
									</cfloop>
									</cfoutput>
								}
</script>
 
<!--- form --->
 
<td>
												 <!--- sending text value, product type and total forecast to the js function --->
												 <select name="selPostPay" onChange="PrePaidChoices(this.value);">
												 	<option value="" selected="selected">PostPay Val</option>
													<cfloop query="rtnGetWQuotaUnits">
														<option value="#rtnGetWQuotaUnits.units#">#rtnGetWQuotaUnits.units#</option>
													</cfloop>
												 </select>
											</td>
											<td id="#qStrFTEmp.currentRow#_W_percent">0.0%</td>
											
											<td>
												 <!--- sending text value, product type and total forecast to the js function --->
												 <select name="SelPrepaid">
												 	<option value="" >PrePaid Val</option>
													<!--- <cfloop query="rtnGetPQuotaUnits">
														<option value="#rtnGetPQuotaUnits.units#">#rtnGetPQuotaUnits.units#</option>
													</cfloop> --->
												 </select>
											</td>
											<td id="#qStrFTEmp.currentRow#_PrePaid_percent">0.0%</td>

Open in new window

0
Comment
Question by:rudodoo
[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
2 Comments
 
LVL 19

Accepted Solution

by:
erikTsomik earned 500 total points
ID: 22618771
try ot ajacfc, or cfajax frameworks it will save you time
0
 

Author Comment

by:rudodoo
ID: 22618885
This is pretty urgent can you take a look at our code and guide me through it.  I'm new to Ajax and I really don't understand it to well.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

726 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