Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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