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

List box-updating and pre-populating

Status
Not open for further replies.

igendreau

Programmer
Dec 8, 2003
7
US
I'm creating a page to edit/update a record. Part of the record is a field that's a list box. I want the choices of the list box to come from a recordset (that's no problem. I did that on the page before where the user originally entered the record). But I want the default value of the list box to be the value that was originally entered. So you get the value currently in the database, and clicking gives you all the options available to you (which come from a different table).

For whatever reason, I can get either the existing value, or all the available values, but not a combo of both. Any help would be appreciated.
 
Without getting into your programming language of choice, you need to modify the dropdown option to reflect the existing value by setting selected.
Code:
...
<option value="firstval" [COLOR=blue]selected="selected"[/color]>firstval</option>
<option value="secval">secval</option>

Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
 
Sorry, probably could have mentioned that for you. I am using classic ASP... writing everything in vbscript.
 
And here is the code populating my list box. It correctly gives you the list of correct choices, but doesn't accurately set the initial value to be equal to what's already been written to the database.

<select name="cboActivity" id="cboActivity">
<%While (NOT rsActivities.EOF)%>
<option value="<%=(rsActivities.Fields.Item("Activity").Value)%>"><%=(rsActivities.Fields.Item("Activity").Value)%></option>
<%rsActivities.MoveNext()
Wend
If (rsActivities.CursorType > 0) Then
rsActivities.MoveFirst
Else
rsActivities.Requery
End If
%>
</select>
 
Code:
<%While (NOT rsActivities.EOF)%>
<option value="<%=(rsActivities.Fields.Item("Activity").Value)%>"
[blue]<%IF CurrentValueVariable = rsActivities.Fields.Item("Activity").Value THEN%>
selected="selected"
<%END IF%>[/blue]
><%=(rsActivities.Fields.Item("Activity").Value)%></option>
<%rsActivities.MoveNext()

Or something like that. You need to compare the values and set the selected option.

Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top