Link to home
Start Free TrialLog in
Avatar of Eric Bourland
Eric BourlandFlag for United States of America

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Eric Bourland

ASKER

Hmmm.... got it. I'll try this. =)
=)

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
p.s. Also thank you and credit to _agx_ for helping me with previous question -- code from which question appears above. =)