Solved

setting up a SELECT menu -- how to indicated selected value -- this time without a ValueList

Posted on 2014-12-23
4
97 Views
Last Modified: 2014-12-23
ColdFusion 11

This question is similar to the last one. Changing a CFSELECT to a SELECT menu. My goals are to populate the SELECT menu using query output, and also indicate the selected value of an existing record.

Here's the old code:

         <p><strong>User Role:</strong></p>      
<!--- this query selects Titles from OSMVISTAUserRoleLookup --->
<cfquery datasource="#APPLICATION.dataSource#" name="GetUserRoles">
        SELECT  RecordID
				,UserRoleID
				,UserRole
        FROM    OSMVISTAUserRoleLookup
</cfquery>

<cfselect size="1" tabindex="1" name="UserRoleID" value="UserRoleID" display="UserRole" multiple="no" query="GetUserRoles" queryPosition="below" selected="#qry_editUser.UserRoleID#">
                 <option value=""> Select User Role </option>
                </cfselect> 

Open in new window


Here's the new code I have been wrestling with -- it throws an error -- I think because I do not need a value list this time. There can be only one selected value.

 
         <p><strong>User Role:</strong></p>      
         
<!--- this query selects UserRole, UserRoleID from table OSMVISTAUserRoleLookup --->
<!--- a user can have only one UserRoleID: '1' if Admin; '3' if Team --->

<cfquery datasource="#application.dataSource#" name="GetUserRoles">
        SELECT  UserRoleID, UserRole
        FROM OSMVISTAUserRoleLookup
</cfquery>

       
<!--- query getSelected requests UserRoleID value already assigned to the current user; from table OSMVISTAUsers --->
  <cfquery datasource="#application.datasource#" name="getSelected">
     SELECT UserRoleID
     FROM OSMVISTAUsers
     WHERE UserRoleID = <cfqueryparam value="#val(form.UserRoleID)#" cfsqltype="cf_sql_integer">
</cfquery>  
  
<!--- convert assigned UserRoleID values into a comma separated value list --->
     <cfset selectedRoles = valueList(getSelected.UserRoleID)>  
 
 
   <!--- assuming #selectedRoles# is always defined --->
 <select size="3" name="UserRoleID" tabindex="3">
       <option value=""> Select User Role: </option>
      <cfoutput query="getSelected">
          <option value="#UserRoleID#" <cfif listFindNoCase(selectedRoles, UserRoleID)>selected</cfif>>
           #UserRole#
        </option>
     </cfoutput>
</select> 

Open in new window


I think I need to use a function other than valueList and listFindNoCase? Thank you again for your help. =)

Eric
0
Comment
Question by:Eric Bourland
  • 3
4 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 40515856
Hey Eric,
Looks like you are looping through the wrong query.  You want your select list to include ALL possible roles, not just the selected ones.   Wouldn't that be the GetuserRoles query like this?

 <select size="3" name="UserRoleID" tabindex="3">
       <option value=""> Select User Role: </option>
       <cfoutput query="GetUserRoles">
          <option value="#GetUserRoles.UserRoleID#" <cfif listFindNoCase(selectedRoles, GetUserRoles.UserRoleID)>selected</cfif>>
           #UserRole#
          </option>
       </cfoutput>
</select>
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40515857
Hmmm.... got it. I'll try this. =)
0
 
LVL 3

Author Closing Comment

by:Eric Bourland
ID: 40515859
=)

I get it. I see what I was doing.

gdemaria, thank you as always. I hope this finds you well, and enjoying a restful holiday. Take good care.

Eric
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40515861
p.s. Also thank you and credit to _agx_ for helping me with previous question -- code from which question appears above. =)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 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

10 Experts available now in Live!

Get 1:1 Help Now