Solved

trouble with SELECT field

Posted on 2014-04-25
4
258 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 500 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
Coldfusion 8 equivalent of the cf9 "new" 4 57
Weird Behavior in ColdFusion 8 84
Coldfusion scheduled tasks as one task 2 92
ColdFusion 10 Error 2 71
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…
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

756 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