Solved

setting up a SELECT menu -- how to indicated selected value

Posted on 2014-12-23
3
135 Views
Last Modified: 2014-12-23
ColdFusion 11

I am trying to use a select menu to display locations stored in a database table, and to highlight the "selected" location after the form is submitted.

I had this working properly using CFSELECT, but I want to stop using CFFORM and CFSELECT and use plain FORM and SELECT tags.

Here is what I have got so far:

Queries:
 
<!--- query getLocations requests all locations --->       
  <cfquery datasource="#application.datasource#" name="getLocations">
       SELECT  LocationID, LocationName
       FROM    OSMVISTALocationLookup
       ORDER BY LocationName ASC
  </cfquery>       
       
<!--- query getSelectedLocations requests already assigned to the current document --->
  <cfquery datasource="#application.datasource#" name="getSelectedLocations">
     SELECT LocationID
     FROM   OSMDocHasLocation 
     WHERE DocumentID = <cfqueryparam value="#val(form.DocumentID)#" cfsqltype="cf_sql_integer">
</cfquery>  
  
<!--- convert assigned DocumentID values into a comma separated value list --->
     <cfset selectedLocations = valueList(getSelectedLocations.LocationID)>  
 

Open in new window

OLD code:
<!--- <cfoutput>       
<cfselect size="10" class="adminSelect" name="LocationID" value="LocationID" display="LocationName" multiple="yes" query="getLocations" queryPosition="below" selected="#selectedLocations#" tabindex="10">
                 <option value=""> Select Region: </option>
              </cfselect>
 </cfoutput>--->

Open in new window


New code I am trying out:

 <select size="10" name="LocationID" multiple="yes" tabindex="10">

<option value=""> Select Region: </option>
 
  <cfoutput> 
 <option value="LocationID" <cfif selectedLocations>selected</cfif>> #getLocations.LocationName# </option>
  </cfoutput>

</select>

Open in new window


How should I indicate "selected". I oughtta know this by now but am not finding examples in other work I have done.

Thanks as always.

Eric
0
Comment
Question by:Eric Bourland
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 40515525
It sounds like #selectedLocations# can contain multiple id's, so use list functions. Something like:

  <!--- assuming #selectedLocations# is always defined --->
 <select size="10" name="LocationID" multiple="yes" tabindex="10">
       <option value=""> Select Region: </option>
      <cfoutput query="getLocations">
          <option value="#LocationID#" <cfif listFindNoCase(selectedLocations, LocationID)>selected</cfif>>
           #LocationName#
        </option>
     </cfoutput>
</select>
0
 
LVL 3

Author Closing Comment

by:Eric Bourland
ID: 40515539
Sweet. This is exactly what I was trying to figure out.

_agx_, thank you as always.

I hope your holiday is passing sweet and slow. Take good care.

Eric
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40515952
You're welcome and hope you have a Merry Christmas :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

26 Experts available now in Live!

Get 1:1 Help Now