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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically repopulate SELECT 1

Status
Not open for further replies.

MorganGreylock

Programmer
Joined
Jan 30, 2001
Messages
223
Location
US
Hello,

I'm trying to make a 'member info update page' where people can update their bio information. Mostly it works fine, although I'm running into a difficult due to the fact that my original signup form had a dropdown list for states... it looked like the following:

<select name=&quot;state&quot;>
<cfinclude template=&quot;template_state_select.cfm&quot;>
</select>

Where template_state_select.cfm contained the following:
<option value=&quot;0&quot;>--Select State--
<option value=&quot;AL&quot;>Alabama
<option value=&quot;AK&quot;>Alaska
<option value=&quot;AZ&quot;>Arizona
<option value=&quot;AR&quot;>Arkansas
<option value=&quot;CA&quot;>California
......


That way, I didn't have to type in that code (used many times on this site) over and over again, and it worked perfectly.

Now the problem rises when I want them to update their information. I have dynamically populated text boxes with
their name, address, etc, but I want the state field to remain a dropdown list, but be populated with the state that they chose. Note that I recorded the 2-letter abbrevation. I have that value, and *could* put that value back into a text box, but I think that would look cheesy and want to keep the dropdown list. Short of doing a <if state=ak then state = Alaska, if state=ca then state=california, etc etc., anyone have any idea how I can do this?

I've already solved half the problem, and heres what I've come up with... I think it will work:

<select name=&quot;state&quot;>
<cfinclude template=&quot;template_state_select.cfm&quot;>
<option value=#state# SELECTED>XXXXXXXX
</select>


I have the value from #state#, but I dont know how to get the full State name to replace the XXXXXXXX... Any suggestions?

I think that since the only data I have is the two letter abbreviation, that I'm stuck with a huge CFSWITCH statement, but you never know... thought maybe CF might have some dandy little state-lookup feature or something. [smile]



Thanks in advance.

Morgan
 
Hey Morgan,

I think this will do what you want:

In template_state_select.cfm

<cfparam name=&quot;defaultSate&quot; default=&quot;&quot;>

<option value=&quot;0&quot;>--Select State--
<option value=&quot;AL&quot;<cfif defaultState is &quot;AL&quot;> selected=&quot;yes&quot;</cfif>>Alabama
<option value=&quot;AK&quot;<cfif defaultState is &quot;AK&quot;> selected=&quot;yes&quot;</cfif>>Alaska
......


And in your other templates:

<select name=&quot;state&quot;>
<cfset defaultState=theirState>
<cfinclude template=&quot;template_state_select.cfm&quot;>
</select>

This will allow it to work in any template whether you're passing it a default value or not.

Hope this helps,
GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top