Solved

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

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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

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…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

728 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