Solved

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

Posted on 2014-12-23
3
138 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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