Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFSELECT pre-select from data base 1

Status
Not open for further replies.

geokor

Programmer
Aug 16, 2000
126
US
I have a CFSELECT box that is hard coded with all 50 state names (abbreviations). I'd like to pre-select or highlight the state that exists for each record as it comes up. The box list exists to allow changes to be made.

I've tried using "selected" and "display" but no luck. Any ideas? Thanks.
George K

<cfselect name=&quot;state&quot;
size=&quot;1&quot;
message=&quot;Please enter a two character state abbreviation.&quot;
value=&quot;#UCase(trim(getcustinfo.state))#&quot;
selected==&quot;#UCase(trim(getcustinfo.state))#&quot;
required=&quot;Yes&quot;
display==&quot;#UCase(trim(getcustinfo.state))#&quot;>
<option value =&quot;AL&quot;>ALABAMA
<option value =&quot;AK&quot;>ALASKA
etc.
 
Since you already hardcoded the select input, why don't you use the standard select?

You can try to code something like this:

<cfoutput>
<option value =&quot;AL&quot;
<cfif UCase(trim(getcustinfo.state))EQ &quot;AL&quot;>
selected
</cfif>
>ALABAMA
<option value =&quot;AK&quot;
<cfif UCase(trim(getcustinfo.state))EQ &quot;AK&quot;>
selected
</cfif>
>ALASKA
...
</cfoutput>

 
I only want to select one state - the one that is returned from the data base as being that customer's residence. In other words, if John Doe lives in NY, then I'd like the list to include all 50 states, with NY already preselected. But if Jane Doe lives in Ohio, I'd like all 50 to be listed but have OH preselected.
I have managed a work-around. I am selecting the resident state and having it listed as an OPTION BEFORE I generate the list. Since it appears as the first state on the list, it is automatically selected. The only problem is it is listed again in the 50 states. Oh well...
Thanks!
 
The initial responce was correct.

You need to pull the state from the DB and do this:
<cfoutput>
<option value =&quot;AL&quot; <cfif getcustinfo.state EQ &quot;AL&quot;>Selected</cfif>>Alabama</option>
<option value =&quot;AK&quot; <cfif getcustinfo.state EQ &quot;AK&quot;>Selected</cfif>>Alaska</option>
</cfoutput>

Only one will be selected while the rest of the items will
still be in the select box.

Chad

 
I handled that problem like this: I have all the states in a table in my database which is queried with get_states. #state# is the customer's state which he already selected in a previous encounter. My solution is not pretty, and codesweeper hates it, but it works.

<CFSELECT name=&quot;State&quot; required=&quot;Yes&quot;>
<CFLOOP query=&quot;get_states&quot;>
<OPTION value=&quot;#get_states.abbrev#&quot;
<CFIF #get_states.abbrev# is #state#>Selected</CFIF>
>#get_states.name#
</CFLOOP>
</CFSELECT>

David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top