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

Listbox

Status
Not open for further replies.

JohannIcon

Programmer
Sep 3, 2002
440
MT
Hi All,

I have a list box and the user can choose an item from the list and then I am displaying it in a textbox. However what i wish to do is set the list box to the item the user selects when the asp is reloaded from the form.

I hope I have made myslef clear

Thanks for your help
 
Is the listbox getting populated from a database?
If so,get the value of the selected item and pass it as a querystring to the page when you reload it. And then in the code where it populates the listbox (in a loop) , check whether the value is equal to the querystring and then make it selected.
 
set objRS = objConn.execute("SELECT valueField, descriptionField FROM myTable")

selectChoice = request("mySelect")
optionStr = &quot;<option value=''>Choose One&quot;
do while not objRS.eof
if objrs(&quot;valueField&quot;) = selectChoice then keyWord = &quot;SELECTED&quot; else keyWord = &quot;&quot;
optionStr = optionStr & &quot;<option value='&quot;& objRS(&quot;valueField&quot;) & &quot;' &quot; & keyWord & &quot;>&quot; & objRS(&quot;descriptionField&quot;)

objrs.movenext
loop -----------------------------------------------------------------
&quot;C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg.&quot;
- Bjarne Stroustrup

mikewolf@tst-us.com
 
Thanks mwolf00,

I tried to adopt it to my situation and did this:-

Dim RSYear,selectChoice,optionStr,keyWord

selectChoice = request(&quot;FilterYear&quot;)
Set RSYear = Server.CreateObject (&quot;ADODB.Recordset&quot;)
RSYear.ActiveConnection = dbcon

RSYear.Open (&quot;SELECT DISTINCT ArtikliYear FROM Artikli ORDER BY ArtikliYear DESC&quot;)

RSYear.MoveFirst

if selectChoice <> &quot;&quot; then

optionStr = &quot;<option value=''>Choose One&quot;
do while not RSYear.eof
if RSYear(&quot;ArtikliYear&quot;) = selectChoice then keyWord = &quot;SELECTED&quot; else keyWord = &quot;&quot;
optionStr = optionStr & &quot;<option value='&quot;& RSYear(&quot;ArtikliYear&quot;) & &quot;' &quot; & keyWord & &quot;>&quot; & RSYear(&quot;ArtikliYear&quot;)

RSYear.movenext
loop
else
While Not RSYear.Eof

Response.Write (&quot;<OPTION VALUE=&quot;&quot;&quot; & RSYear.Fields(&quot;ArtikliYear&quot;) & &quot;&quot;&quot;>&quot; & (RSYear.Fields(&quot;ArtikliYear&quot;)) & &quot;</OPTION>&quot;)

RSYear.MoveNext
Wend

end if

but the list box is not being populated now when I press the submit button and reload the ASP.
 
Dim RSYear,selectChoice,optionStr,keyWord

selectChoice = request(&quot;FilterYear&quot;)
Set RSYear = Server.CreateObject (&quot;ADODB.Recordset&quot;)
RSYear.ActiveConnection = dbcon

RSYear.Open (&quot;SELECT DISTINCT ArtikliYear FROM Artikli ORDER BY ArtikliYear DESC&quot;)

RSYear.MoveFirst

if selectChoice <> &quot;&quot; then

optionStr = &quot;<option value=''>Choose One&quot;
do while not RSYear.eof
if RSYear(&quot;ArtikliYear&quot;) = selectChoice then keyWord = &quot;SELECTED&quot; else keyWord = &quot;&quot;
optionStr = optionStr & &quot;<option value='&quot;& RSYear(&quot;ArtikliYear&quot;) & &quot;' &quot; & keyWord & &quot;>&quot; & RSYear(&quot;ArtikliYear&quot;)

RSYear.movenext
loop
response.write optionStr
else
While Not RSYear.Eof

Response.Write (&quot;<OPTION VALUE=&quot;&quot;&quot; & RSYear.Fields(&quot;ArtikliYear&quot;) & &quot;&quot;&quot;>&quot; & (RSYear.Fields(&quot;ArtikliYear&quot;)) & &quot;</OPTION>&quot;)

RSYear.MoveNext
Wend

end if -----------------------------------------------------------------
&quot;The difference between 'involvement' and 'commitment' is like an eggs-and-ham breakfast: the chicken was 'involved' - the pig was 'committed'.&quot;
- unknown

mikewolf@tst-us.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top