[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

trouble with SELECT field

Posted on 2014-04-25
4
Medium Priority
?
264 Views
Last Modified: 2014-04-25
ColdFusion 9
MS SQL Server 2012

Hi. I am having a little trouble with a SELECT menu field in a form. The SELECT menu is a dropdown list of USA states.

When I edit a database record, I want the SELECT menu to display, or highlight, the value that is already in the database table. For example -- "Kentucky".

I have stopped using CFFORM and CFSELECT -- mainly because I want to get away from using the scripts in CFIDE. I am using plain ol' FORM, INPUT, and SELECT fields.

Here is the SELECT menu I am using, which does not display the correct selected value when I edit a record. What am I missing?

I think I might need to set up a CFIF statement -- if getProjectDetails.state has a value, then set that value as SELECTED ... but I am not sure what that looks like. =)

Thank you as always for your help.

Eric

Query:

<!--- get data from table #REQUEST.ProjectsTable# and convert the data into form variables --->
			  <cfquery name="getProjectDetails" datasource="#application.datasource#">
			    SELECT projectID
,ProjectName
,OSMVISTA
,Supervisor
,Address
,City
,State
,ZIP
,County
,Telephone
,Email
,Website
,CongressionalDistrict
,ProjectMission
,ProjectDescription
,DateCreated
,DateModified
,ParentID
,SortOrder
,projectKeywords
,projectDescriptionMeta
,projectOwner
,projectAuthor
,projectTitletag
,Archive
,Photo144
,Photo288
,Photo400
,Photo640
,Photo800
,projectPhoto
,leaderphoto

                FROM #REQUEST.ProjectsTable#
                WHERE projectID = <cfqueryparam cfsqltype="cf_sql_integer" value="#val(form.projectID)#">
 			  </cfquery>

  			<cfloop index="aCol" list="#getProjectDetails.columnList#">
			       <cfset "form.#aCol#" = getProjectDetails[aCol][getProjectDetails.currentRow]>
			  </cfloop>

Open in new window



SELECT Menu:
  <label for="State"><h3>State:</h3></label>
   <select size="10"
    name="State"
    value="State"
    multiple="no"
	tabindex="6"
    required="yes">
<option value="" <cfoutput>selected="#getProjectDetails.State#"</cfoutput>>Select a State</option> 
<option value="AL">Alabama</option> 
<option value="AK">Alaska</option> 
<option value="AZ">Arizona</option> 
<option value="AR">Arkansas</option> 
<option value="CA">California</option> 
<option value="CO">Colorado</option> 
<option value="CT">Connecticut</option> 
<option value="DE">Delaware</option> 
<option value="DC">District Of Columbia</option> 
<option value="FL">Florida</option> 
<option value="GA">Georgia</option> 
<option value="HI">Hawaii</option> 
<option value="ID">Idaho</option> 
<option value="IL">Illinois</option> 
<option value="IN">Indiana</option> 
<option value="IA">Iowa</option> 
<option value="KS">Kansas</option> 
<option value="KY">Kentucky</option> 
<option value="LA">Louisiana</option> 
<option value="ME">Maine</option> 
<option value="MD">Maryland</option> 
<option value="MA">Massachusetts</option> 
<option value="MI">Michigan</option> 
<option value="MN">Minnesota</option> 
<option value="MS">Mississippi</option> 
<option value="MO">Missouri</option> 
<option value="MT">Montana</option> 
<option value="NE">Nebraska</option> 
<option value="NV">Nevada</option> 
<option value="NH">New Hampshire</option> 
<option value="NJ">New Jersey</option> 
<option value="NM">New Mexico</option> 
<option value="NY">New York</option> 
<option value="NC">North Carolina</option> 
<option value="ND">North Dakota</option> 
<option value="OH">Ohio</option> 
<option value="OK">Oklahoma</option> 
<option value="OR">Oregon</option> 
<option value="PA">Pennsylvania</option> 
<option value="RI">Rhode Island</option> 
<option value="SC">South Carolina</option> 
<option value="SD">South Dakota</option> 
<option value="TN">Tennessee</option> 
<option value="TX">Texas</option> 
<option value="UT">Utah</option> 
<option value="VT">Vermont</option> 
<option value="VA">Virginia</option> 
<option value="WA">Washington</option> 
<option value="WV">West Virginia</option> 
<option value="WI">Wisconsin</option> 
<option value="WY">Wyoming</option>
</select>

Open in new window

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
  • 2
4 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 40023628
Yep, you need a cfif. Check the option value. If it matches, mark the option as selected:

<option value="AL"
       <cfif getProjectDetails.State EQ "AL">selected</cfif>  >Alabama</option>

Of course you'd need to do that for *each* state <option>. A lot of changes if the list is really hard coded.  Hopefully you're storing the states in a db table, and populating the list with a query :) Then it's just:

(Watch the line wrapping...)

       <cfquery name="getStates">
        SELECT TheStateCode, TheStateTitle FROM ....
       </cfquery>

       <select name="state" ...>
           ...
        <cfoutput query="getStates">
              <option value="#getStates.TheStateCode#"
       <cfif getProjectDetails.State EQ getStates.TheStateCode>selected</cfif>>#getStates.TheStateTitle</option>
        </cfoutput>
        ....
      </select>
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40023636
Makes sense. I've got all of the states in a table. I will try it out! brb
0
 
LVL 3

Author Closing Comment

by:Eric Bourland
ID: 40023664
Worked perfectly. _agx_, thank you as always. I'll try not to bug you again this weekend. =) Have a great weekend. Eric


    <!--- this query selects State Titles from tbl_NBPTS_Lookup_State --->
<cfquery datasource="#APPLICATION.dataSource#" name="GetStates">
        SELECT StateName
        FROM tbl_NBPTS_Lookup_State
</cfquery>

<li>
  <label for="State"><h3>State:</h3></label>
   <select size="10"
    name="State"
    multiple="no"
	tabindex="6"
    required="yes">
   <cfoutput query="GetStates">
    <option value="#GetStates.StateName#"
	<cfif getProjectDetails.State EQ GetStates.StateName>selected</cfif>>#GetStates.StateName#</option>
    </cfoutput>
</select>


             <span class="form_hint">Select state.</span>           
</li> 

Open in new window

0
 
LVL 52

Expert Comment

by:_agx_
ID: 40023752
Always a pleasure.  Hope you enjoy the weekend!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

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 …
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

656 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