Solved

Reselect my selected multi select list

Posted on 2014-03-25
3
243 Views
Last Modified: 2014-03-26
Hi,

I have a multi select list that I insert into my table.

What I want is to reselect the list if I'm passing the ID for editing.


 <SELECT multiple="multiple" name="SelectDepartmentImpacted" id="SelectDepartmentImpacted" style="width:500px;height:130px;" class="SearchBySelect5"> 
           <cfoutput query="QDepartmentImpacted">
            <CFIF isDefined("QSelectedDepartmentJoint") and #QSelectedDepartmentJoint.RecordCount# gt 0>
    
       <cfif #QDepartmentImpacted.DepartmentImpactedID# eq #QSelectedDepartmentJoint.DepartmentImpactedID# >
     		 			<option value="#QDepartmentImpacted.DepartmentImpactedID#" selected="selected">#QDepartmentImpacted.Department#</option>
     				<cfelse>
     		 			<option value="#QDepartmentImpacted.DepartmentImpactedID#">#QDepartmentImpacted.Department#</option>
     				</cfif>
       <cfelse>
       			  <option value="#QDepartmentImpacted.DepartmentImpactedID#">#QDepartmentImpacted.Department#</option>
       </CFIF>
			 </cfoutput>
            </select> 

Open in new window

0
Comment
Question by:lulu50
3 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 39954935
I made a comma delimited list of all the selected Department IDs  - the list is in the variable AllIDs.

Then I compare the departmentID to the list, if the ID is on the list, then it is selected, if not, it is not selected.

Does this work?

<cfset AllIDs = valueList(QSelectedDepartmentJoint.DepartmentImpactedID)>
<SELECT multiple="multiple" name="SelectDepartmentImpacted" id="SelectDepartmentImpacted" style="width:500px;height:130px;" class="SearchBySelect5"> 
	<cfoutput query="QDepartmentImpacted">
		<cfif listFind(AllIDs,QDepartmentImpacted.DepartmentImpactedID)>
			<option value="#QDepartmentImpacted.DepartmentImpactedID#" selected="selected">#QDepartmentImpacted.Department#</option>
		<cfelse>
			<option value="#QDepartmentImpacted.DepartmentImpactedID#">#QDepartmentImpacted.Department#</option>
		</cfif>
	</cfoutput>
</select> 

Open in new window

0
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 39955350
It will be like this:


<cfset AllIDs = ValueList(QSelectedDepartmentJoint.DepartmentImpactedID)>
<SELECT multiple="multiple" name="SelectDepartmentImpacted" id="SelectDepartmentImpacted" style="width:500px;height:130px;" class="SearchBySelect5">
  <cfloop query="QDepartmentImpacted">
    <option value="#QDepartmentImpacted.DepartmentImpactedID#" <cfif ListContainsNoCase(AllIDs,QDepartmentImpacted.DepartmentImpactedID)>selected</cfif>>#QDepartmentImpacted.Department#</option>
  </cfloop>
</select>

Open in new window


@gdmeria code is also right
0
 

Author Closing Comment

by:lulu50
ID: 39955860
Excellentooooooo !!!!!!!!!!!!

Thank you Thank you and just one more Thank you lol lol
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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