Solved

Drop Down isn't displaying default database value on a row

Posted on 2008-10-22
6
229 Views
Last Modified: 2008-10-27
I'm creating a set of drop downs in Coldfusion and when a user clicks submit he/she should be able to see the default value from the selection that was made.  For a majority of the records displayed on the screen Im able to make this work using some <cfif statements to create conditions.

However, there are some that wont cooperate and displays values that arent whats stored in the table.

The tricky part is that Im able to fix this problem but only if I change the indexed value used on a current condition which is also used to display default values for other records. (Hope that makes sense)

So if I apply the fix for my current problem then other records on the same page will display an incorrect value, and Im back to square one.

I really need some help on this one Ive been racking my brain all night and still havent been able to figure it out.  

Ill attach my code below, let me know if anyone has any questions

FYI - I have posted some comments in my code to help if anyone is willing.  Please help me!!  This project is due today and this is the very last part other than user testing

<!--- Retrieve Part Time employees --->
						 		<cfif isDefined("qStrPTEmp") and qStrPTEmp.recordcount gt 0>
									
									<!--- ptRow represents the row count --->
									<cfset z1_pt = (ptRow * 3)+1>
									<cfset z2_pt = (ptRow * 3)+2>
									<cfset z3_pt = (ptRow * 3)+3>
									
									
									<cfloop from="1" to="#qStrPTEmp.recordcount#" index="pte">
										
										 <cfset ptRow = ptRow + 1> 
										<tr>
											
											<td>
												#qStrPTEmp.PosNbr[pte]#
											</td>
											<td>
												#qStrPTEmp.Emplid[pte]#
											</td>
											<td nowrap="nowrap">
												 #qStrPTEmp.Name[pte]#<input type="hidden" name="#ptRow#_RowKey" value="#ptRow#_#qStrPTEmp.Emplid[pte]#_#qStrPTEmp.PosNbr[pte]#_#qStrPTEmp.ps_location[pte]#_#qStrPTEmp.hours_factor[pte]#">
											</td>			
											<td>#qStrPTEmp.Status[pte]#</td>
											
											<td nowrap="nowrap"> #qStrPTEmp.compplan[pte]# </td>
											
											
											<td nowrap="nowrap"> #qStrPTEmp.quotaplan[pte]# </td>
											
											<cfparam name="form.selAssignedStatus_#qStrPTEmp.Emplid[pte]#" default="PT">
											
											<td>
											<cfif qStrPTEmp.approved[pte] eq 1>
												#qStrPTEmp.Status[pte]#
											<cfelse>
												<select name="selAssignedStatus_#qStrPTEmp.Emplid[pte]#" onChange="empStatus(this.value,'#qStrPTEmp.Emplid[pte]#');">
													<option value="PT" <cfif Evaluate('form.selAssignedStatus_#qStrPTEmp.Emplid[pte]#') eq 'PT'> selected </cfif>>PT</option>
													<option value="FT" <!--- <cfif Evaluate('form.selAssignedStatus_#qStrPTEmp.Emplid[pte]#') eq 'FT'> selected </cfif> --->>FT</option>
													<option value="LOA" <!--- <cfif Evaluate('form.selAssignedStatus_#qStrPTEmp.Emplid[pte]#') eq 'LOA'> selected </cfif> --->>LOA</option>
												</select>
											</cfif>
											</td>
											<!--- Use this line to help setup condiitions on what to set [z1_pt] too--->
											 <td><cfoutput> #PtRow# &nbsp; #z1_pt# &nbsp;  #qStMgrForecast.assigned[z1_pt]#</cfoutput></td> 
											<!---  Select from PostPay  Choices --->
											<td>
											 <cfif qStrPTEmp.approved eq 1>
												#qStMgrForecast.assigned[z1_pt]#
											<cfelse> 
												 <select name="selPostPay_PT_#qStrPTEmp.Emplid[pte]#" onChange="getPrePaidChoices_PT(this.value);" >
												 	<cfif qStMgrForecast.assigned[z1_pt] eq "">
												 		<option value=""></option>
													<cfelse>
														<!--- Here is where I'm having the hardest trouble  --->
														<cfif qStMgrForecast.assigned[z1_pt] eq 0>
															<cfset z1_pt=z1_pt+3>
														<cfelseif z1_pt gt qStMgrForecast.assigned[z1_pt]>
															<cfset z1_pt=z1_pt-3>
															<!---  I can get the correct assigned value to default to the drop down box if I use this instead --->
														 	<!--- <cfset z1_pt=z1_pt> --->
														<cfelseif z1_pt lt qStMgrForecast.assigned[z1_pt]>
															<cfset z1_pt=z1_pt-3>
														<cfelse>
															<cfset z1_pt=z1_pt>
														</cfif>
														
														<option value="#qStMgrForecast.assigned[z1_pt]#" <cfif form.selPostPay_PT eq qStMgrForecast.assigned[z1_pt]> selected</cfif>>#qStMgrForecast.assigned[z1_pt]#</option>
														<cfset z1_pt=z1_pt+3>
													</cfif>
														<option value="#postDefault_PT#" <cfif isDefined("form.selPostPay_PT_#qStrPTEmp.Emplid[pte]#") and Evaluate("form.selPostPay_PT_#qStrPTEmp.Emplid[pte]#") eq #postDefault_PT#>selected</cfif>>#postDefault_PT#</option>
													<cfloop query="rtnGetWQuotaUnits">
														<option value="#rtnGetWQuotaUnits.units#" <cfif isDefined("form.selPostPay_PT_#qStrPTEmp.Emplid[pte]#") and  Evaluate("form.selPostPay_PT_#qStrPTEmp.Emplid[pte]#") eq rtnGetWQuotaUnits.units> selected</cfif>>#rtnGetWQuotaUnits.units#</option>
													</cfloop>
													
												 </select>
												
											 </cfif> 
											</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
  • 4
  • 2
6 Comments
 
LVL 8

Expert Comment

by:eszaq
ID: 22776647
You have much more code then you need. I need time to go through it and get the logic behind (to understand what you are trying to do. For example, this your block of code.
<cfif qStMgrForecast.assigned[z1_pt] eq 0>
  <cfset z1_pt=z1_pt+3>
<cfelseif z1_pt gt qStMgrForecast.assigned[z1_pt]>
  <cfset z1_pt=z1_pt-3>
  <!---  I can get the correct assigned value to default to the drop down box if I use this instead --->
   <!--- <cfset z1_pt=z1_pt> --->
<cfelseif z1_pt lt qStMgrForecast.assigned[z1_pt]>
  <cfset z1_pt=z1_pt-3>
<cfelse>
  <cfset z1_pt=z1_pt>
</cfif>

All you need to achieve the same result is:
<cfif qStMgrForecast.assigned[z1_pt] eq 0>
  <cfset z1_pt=z1_pt+3>
<cfelseif qStMgrForecast.assigned[z1_pt] neq z1_pt>
  <cfset z1_pt=z1_pt-3>
</cfif>

Also, it seems that you have more variables then you need.  But without knowing what you are trying to do it will take me awhile to figure out from your code what changes need to be made. Your snippet does not even have closing tag for outer <cfloop>
0
 

Author Comment

by:rudodoo
ID: 22777366
I'm trying to display the default value for all part time employee.  The thing is that all Full time employees must have the same quota.  So that makes it a little easier.  However, the Part Time employees can have different assigned quotas so they each have there very own drop down.  I can put the rest of the code in the attachment for you

FYI - I already added your code into it
<!--- Retrieve Part Time employees --->
						 		<cfif isDefined("qStrPTEmp") and qStrPTEmp.recordcount gt 0>
									
									<!--- ptRow represents the row count --->
									<cfset z1_pt = (ptRow * 3)+1>
									<cfset z2_pt = (ptRow * 3)+2>
									<cfset z3_pt = (ptRow * 3)+3>
									
									<cfset z1pt=4>
									<cfset z2pt=5>
									<cfset z3pt=6	>
									<cfloop from="1" to="#qStrPTEmp.recordcount#" index="pte">
									 <cfset z1pt=z1pt+1> 
									<!--- <cfset z1pt=z1pt+1>>	
									<cfset z2pt=z2pt+1>
									<cfset z3pt=z3pt+1> --->
										 <cfset ptRow = ptRow + 1> 
										<tr>
											
											<td>
												#qStrPTEmp.PosNbr[pte]#
											</td>
											<td>
												#qStrPTEmp.Emplid[pte]#
											</td>
											<td nowrap="nowrap">
												 #qStrPTEmp.Name[pte]#<input type="hidden" name="#ptRow#_RowKey" value="#ptRow#_#qStrPTEmp.Emplid[pte]#_#qStrPTEmp.PosNbr[pte]#_#qStrPTEmp.ps_location[pte]#_#qStrPTEmp.hours_factor[pte]#">
											</td>			
											<td>#qStrPTEmp.Status[pte]#</td>
											
											<td nowrap="nowrap"> #qStrPTEmp.compplan[pte]# </td>
											
											
											<td nowrap="nowrap"> #qStrPTEmp.quotaplan[pte]# </td>
											
											<cfparam name="form.selAssignedStatus_#qStrPTEmp.Emplid[pte]#" default="PT">
											
											<td>
											<cfif qStrPTEmp.approved[pte] eq 1>
												#qStrPTEmp.Status[pte]#
											<cfelse>
												<select name="selAssignedStatus_#qStrPTEmp.Emplid[pte]#" onChange="empStatus(this.value,'#qStrPTEmp.Emplid[pte]#');">
													<option value="PT" <cfif Evaluate('form.selAssignedStatus_#qStrPTEmp.Emplid[pte]#') eq 'PT'> selected </cfif>>PT</option>
													<option value="FT" <!--- <cfif Evaluate('form.selAssignedStatus_#qStrPTEmp.Emplid[pte]#') eq 'FT'> selected </cfif> --->>FT</option>
													<option value="LOA" <!--- <cfif Evaluate('form.selAssignedStatus_#qStrPTEmp.Emplid[pte]#') eq 'LOA'> selected </cfif> --->>LOA</option>
												</select>
											</cfif>
											</td>
											<!--- Use this line to help setup condiitions on what to set [z1_pt] too--->
											<!---  <td><cfoutput> #PtRow# &nbsp; #z1_pt# &nbsp;  #qStMgrForecast.assigned[z1_pt]#</cfoutput></td> ---> 
											<!---  Select from PostPay  Choices --->
											<td>
											 <cfif qStrPTEmp.approved eq 1>
												#qStrPTEmpAssigned.assigned[z1pt]#
											<cfelse> 
												 <select name="selPostPay_PT_#qStrPTEmp.Emplid[pte]#" onChange="getPrePaidChoices_PT(this.value);" >
												 	<cfif qStMgrForecast.assigned[z1_pt] eq "">
												 		<option value=""></option>
													<cfelse>
													<cfif qStMgrForecast.assigned[z1_pt] eq 0>
														<cfset z1_pt=z1_pt+3>
													<cfelseif qStMgrForecast.assigned[z1_pt] neq z1_pt>
													  <cfset z1_pt=z1_pt-3>
													</cfif>
 
														
														<option value="#qStMgrForecast.assigned[z1_pt]#" <cfif form.selPostPay_PT eq qStMgrForecast.assigned[z1_pt]> selected</cfif>>#qStMgrForecast.assigned[z1_pt]#</option>
														<cfset z1_pt=z1_pt+3>
													</cfif>
														<option value="#postDefault_PT#" <cfif isDefined("form.selPostPay_PT_#qStrPTEmp.Emplid[pte]#") and Evaluate("form.selPostPay_PT_#qStrPTEmp.Emplid[pte]#") eq #postDefault_PT#>selected</cfif>>#postDefault_PT#</option>
													<cfloop query="rtnGetWQuotaUnits">
														<option value="#rtnGetWQuotaUnits.units#" <cfif isDefined("form.selPostPay_PT_#qStrPTEmp.Emplid[pte]#") and  Evaluate("form.selPostPay_PT_#qStrPTEmp.Emplid[pte]#") eq rtnGetWQuotaUnits.units> selected</cfif>>#rtnGetWQuotaUnits.units#</option>
													</cfloop>
													
												 </select>
												
											 </cfif> 
											</td>
											
										
										<!--- td><cfoutput>#PtRow# #z2_pt# -- #qStMgrForecast.assigned[z2_pt]#</cfoutput></td> --->
											
												<!--- If VP as already approved --->
											<td>
											<cfif qStrPTEmp.approved eq 1>
												#qStrPTEmpAssigned.assigned[z2pt]#
											<cfelse> 
											
											<!---  Select from PrePay  Choices --->
											 	<select name="selPrePay_PT_#qStrPTEmp.Emplid[pte]#" onChange="getCRChoices_PT(this.value);">
												 	<cfif qStMgrForecast.assigned[z2_pt] eq "">
												 		<option value=""></option>
													<cfelse>
														<cfif qStMgrForecast.assigned[z2_pt] eq 0>
															<cfset z2_pt=z2_pt+3>
														<cfelseif z2_pt gt qStMgrForecast.assigned[z2_pt]>
															<cfset z2_pt=z2_pt-3>
														</cfif>
														
														<option value="#qStMgrForecast.assigned[z2_pt]#" <cfif form.selPrePay_PT eq qStMgrForecast.assigned[z2_pt]> selected</cfif>>#qStMgrForecast.assigned[z2_pt]#</option>
														<cfset z2_pt=z2_pt+3> 
													</cfif>
														<option value="#preDefault_PT#" <cfif isDefined("form.selPrePay_PT_#qStrPTEmp.Emplid[pte]#") and Evaluate("form.selPrePay_PT_#qStrPTEmp.Emplid[pte]#") eq #preDefault_PT#>selected</cfif>>#preDefault_PT#</option>
													<!--- <cfif isDefined("form.selPostPay_PT_#qStrPTEmp.Emplid[pte]#") and Evaluate("form.selPostPay_PT_#qStrPTEmp.Emplid[pte]#") eq #postDefault_PT#> --->
													<cfif isDefined("form.selPostPay_PT_#qStrPTEmp.Emplid[pte]#") and Evaluate("form.selPostPay_PT_#qStrPTEmp.Emplid[pte]#") neq "">
														<cfif isQuery(Evaluate("rtnGetPQuotaUnitsPT_#qStrPTEmp.Emplid[pte]#"))>
															<cfloop query="rtnGetPQuotaUnitsPT_#qStrPTEmp.Emplid[pte]#">
																<option value="#Evaluate('rtnGetPQuotaUnitsPT_#qStrPTEmp.Emplid[pte]#.units')#" <cfif Evaluate("form.SelPrePay_PT_#qStrPTEmp.Emplid[pte]#") eq Evaluate("rtnGetPQuotaUnitsPT_#qStrPTEmp.Emplid[pte]#.units")> selected </cfif>>#Evaluate('rtnGetPQuotaUnitsPT_#qStrPTEmp.Emplid[pte]#.units')#</option>
															</cfloop>
														</cfif>
													</cfif>
											 	</select>
											</cfif>
											</td>
											
											<!--- <td><cfoutput>#z3_pt# -- #qStMgrForecast.assigned[z3_pt]#</cfoutput></td> --->
											<!---  Select from CR  Choices --->
											<td>
											<cfif qStrPTEmp.approved eq 1>
												#qStrPTEmpAssigned.assigned[z3pt]#
											<cfelse>
												
												 <select name="selCR_PT_#qStrPTEmp.Emplid[pte]#" onChange="selectedCRVal_PT(this.value);">
												 	
												 	<cfif qStMgrForecast.assigned[z3_pt] eq "">
												 		<option value=""></option>
													<cfelse>
														<cfif qStMgrForecast.assigned[z3_pt] eq 0>
															<cfset z3_pt=z3_pt+3>
														<cfelseif z3_pt gte qStMgrForecast.assigned[z3_pt]>
															<cfset z3_pt=z3_pt-3>
														<!--- <cfelseif z3_pt lt qStMgrForecast.assigned[z3_pt]> --->
														<cfelse>
															<cfset z3_pt=z3_pt>
														</cfif>
														
															<option value="#qStMgrForecast.assigned[z3_pt]#" <cfif form.selCR_PT eq qStMgrForecast.assigned[z3_pt]> selected</cfif>>#qStMgrForecast.assigned[z3_pt]#</option>
															<cfset z3_pt=z3_pt+3> 
													</cfif>
													<option value="#crDefault_PT#" <cfif isDefined("form.selCR_PT_#qStrPTEmp.Emplid[pte]#") and Evaluate("form.selCR_PT_#qStrPTEmp.Emplid[pte]#") eq crDefault_PT> selected </cfif>>#crDefault_PT#</option>
													<!--- <cfif isDefined("form.SelPrePay_PT_#qStrPTEmp.Emplid[pte]#") and Evaluate("form.SelPrePay_PT_#qStrPTEmp.Emplid[pte]#") eq #preDefault_PT#> --->
													<cfif isDefined("form.SelPrePay_PT_#qStrPTEmp.Emplid[pte]#") and Evaluate("form.SelPrePay_PT_#qStrPTEmp.Emplid[pte]#") neq "">
														<cfif isQuery(Evaluate("rtnGetCRQuotaUnitsPT_#qStrPTEmp.Emplid[pte]#"))>
															<cfloop query="rtnGetCRQuotaUnitsPT_#qStrPTEmp.Emplid[pte]#">
																<option value="#Evaluate('rtnGetCRQuotaUnitsPT_#qStrPTEmp.Emplid[pte]#.units')#" <cfif Evaluate("form.SelCR_PT_#qStrPTEmp.Emplid[pte]#") eq Evaluate("rtnGetCRQuotaUnitsPT_#qStrPTEmp.Emplid[pte]#.units")> selected </cfif>>#Evaluate("rtnGetCRQuotaUnitsPT_#qStrPTEmp.Emplid[pte]#.units")#</option>
															</cfloop>
														</cfif>
													</cfif>
												 </select>
												</cfif>
											</td> 
									   </tr>
									</cfloop>
								<cfelse>
                              		<tr>
                                   		<td colspan="13">There are no Part Time Employees listed as direct reports for this Store Manager position.</td>
                              		</tr>
								</cfif>

Open in new window

0
 

Author Comment

by:rudodoo
ID: 22777765
I used your code and the default value in the databse still did not display.  What happened?
0
Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

 
LVL 8

Expert Comment

by:eszaq
ID: 22777827
I did not claim that my code will fix your problem. I just used it as an example, to show that you can get some things done with fewer lines of code. I have not gone through debugging your code yet.
0
 

Author Comment

by:rudodoo
ID: 22777892
Sorry, I've been working on this project so long its starting to get to me a little.  Please continue I really need some help
0
 

Accepted Solution

by:
rudodoo earned 0 total points
ID: 22779086
Ok I've figured out the solution the index value wasn't set correctly.  Thanks for the help though
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

734 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