Solved

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

Posted on 2014-12-23
4
98 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

786 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