Solved

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

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

9 Experts available now in Live!

Get 1:1 Help Now