Solved

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

Posted on 2014-12-23
4
102 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
[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
  • 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

628 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