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

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

rudodooAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

eszaqCommented:
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
rudodooAuthor Commented:
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
rudodooAuthor Commented:
I used your code and the default value in the databse still did not display.  What happened?
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

eszaqCommented:
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
rudodooAuthor Commented:
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
rudodooAuthor Commented:
Ok I've figured out the solution the index value wasn't set correctly.  Thanks for the help though
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.