?
Solved

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

Posted on 2014-12-23
3
Medium Priority
?
143 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 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