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

Selecting a list item - Filling in a form from stored data in DB 1

Status
Not open for further replies.

cindyhnv

Programmer
May 19, 2004
9
0
0
US
I have a form that has several fields including a Select Field that lists all 50 states. The user select's their state along with the info they enter and it's all stored in the database. I would like to let them "edit" their information if they choose and need to repopulate the form with the data that they initally entered in the form.
I can get the text field data to fill in but I'm having trouble "selecting" their state.
How do I get the form's state list to select the state that is in the database?

Thanks in advance for any help you can provide.

Cindy

"The human mind treats a new idea the way the body treats a strange protein; it rejects it." - P.B Medawar
 
do you want to display the selected field in the database record as the default option when they go back to update their record?
 
Yes. I'd like the "state" they initially entered to show up as the default. But, I would like the rest of the list to still be there so they can change it if they wanted to.


"The human mind treats a new idea the way the body treats a strange protein; it rejects it." - P.B Medawar
 
I reread your post and it seems the above is what you want to do..

Actually it is quite easy.

Before you display the code run a CFQUERY that pulls the value of the record field and just place it in the html code that displays the selected value.

<tr>
<td>
State</td>
<td width="350" align="left">
<select name="Field_State" size="1">
<cfoutput><OPTION VALUE="#YourQueryName.Field_State#" SELECTED#YourQueryName.Field_State#</cfoutput>
<cfoutput query="YourQueryState_List"><option value="#State_Name#">#State_Name#</option></cfoutput></SELECT>
</td>
</tr>

I hope this helps you get started.
 
My example assumed that you had a database table of the states that you would then have to use a query to output the list. If you do not...just replace the "YourQueryState_List" portion of the code with the static state list.
 
Well that appears to be heading in the right direction. But - I'm still doing something wrong -

<tr>
<td>
State</td>
<td width="350" align="left">
<select name="Field_State" size="1">
<cfoutput><OPTION VALUE="#YourQueryName.Field_State#" SELECTED'#YourQueryName.Field_State#'>
<option value='Alabama'>Alabama
<option value='Nevada'>Nevada
<option value='Wyoming'>Wyoming</cfoutput></SELECT>
</td>
</tr>

This is an abbreviated version of what I have now. When the form "fills" in the state field is blank, highlighted (selected) but there is no state name there.

Thanks for your help!


"The human mind treats a new idea the way the body treats a strange protein; it rejects it." - P.B Medawar
 
wait I think I got my code to you wrong it is my HTML set up is wrong.
 
<cfoutput><OPTION VALUE="#YourQueryName.Field_State#" SELECTED>#YourQueryName.Field_State#'</cfoutput>
<option value='Alabama'>Alabama</option>
<option value='Nevada'>Nevada</option>
<option value='Wyoming'>Wyoming</SELECT>
 
-See there is ">" after the selected tag...
-I have moved the cfoutput tags so they just nest the selected value.
-Even though it is not required, I added a closing option tag to each line.
Note the code above does not include the starting code for a select field, I forgot to inlcude it! :)
<select name="Field_State" size="1">


 
This works! It does end up showing the state that was initially selected twice, at the very top of the list and again in it's alphabetical position, but... It works!

Thanks!

"The human mind treats a new idea the way the body treats a strange protein; it rejects it." - P.B Medawar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top