Eric Bourland
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:
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.
I think I need to use a function other than valueList and listFindNoCase? Thank you again for your help. =)
Eric
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>
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>
I think I need to use a function other than valueList and listFindNoCase? Thank you again for your help. =)
Eric
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
=)
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
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
ASKER
p.s. Also thank you and credit to _agx_ for helping me with previous question -- code from which question appears above. =)
ASKER