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

help with populated dropdown

Status
Not open for further replies.

donniea21

MIS
Feb 16, 2001
75
US
I have a dropdown that is popuated from a database..the problem i am having is when the boxes were origionally hard coeded i had:
<select size=&quot;1&quot; name=&quot;cbUser&quot; onChange=&quot;document.forms[0].submit()&quot;>
<option <%if user=&quot;John Doe&quot; then%>selected<%end if%>>John Doe</option>
this was done to main state after the form was submitted to itself...now that i am populating the list by looping i am having trouble with maintain this state this is the code i have right now:
Response.Write(&quot;<option>&quot; & rs(&quot;UserName&quot;) & &quot;</option>&quot;)
i need to figure out how to get that if statement into the loop...it should just be a syntax issue...but i cant seem to get it...Thanks
 
Hi, I am a bit confused but I am sure I can help with a few more details....first are you submitting to itself for a reason or could you submit to the target asp page?

a bit more info would help

Bassguy
 
i am submitting to itself because i have other dropdowns that are created depending on this one..i.e. dpended on which user is selected with this dropdown, there will be another dropdown with custom selection..once all boxes are complete, the form action is then set to the target asp
 
Here is my full code for the loop for this drop down
<%
Do While Not rs.eof
Response.Write(&quot;<option>&quot; & rs(&quot;UserName&quot;) & &quot;</option>&quot;)
rs.movenext
Loop

conn.close
Set conn=Nothing
Set rs=Nothing
%>
 
What I do in situations like that where you want to restate the option selected is to add an extra option before you loop of code (the option selected line)

so it looks like this



<% set rs=server.createobject(&quot;adodb.recordset&quot;)
ssql=&quot;select * from Employees&quot;
rs.open ssql, application(&quot;northwind_Connectionstring&quot;)
rs.movefirst%>
<form action=example.asp>
<%=request(&quot;Employee&quot;)%>
<select name=Employee onchange=document.forms[0].submit()>
<option selected value=<%if len(request(&quot;employee&quot;))=0 then response.write &quot;&quot; else response.write request(&quot;employee&quot;)%> >
<%if len(request(&quot;employee&quot;))=0 then response.write &quot;Please Make Selection&quot; else response.write request(&quot;employee&quot;)%>
</option>
<%do while not rs.eof%>
<option value=&quot;<%=rs(2)&&quot; &quot;&rs(1)%>&quot; ><%=rs(2)&&quot; &quot;&rs(1)%></option>
<%rs.movenext
loop
rs.close
If len(request(&quot;employee&quot;))>0 then

%>





your second dropdown goes here





i just grabbed the employee table in the Northwind database for an example


I hope this helps

bassguy
 
'DECLARE AND SET THE CURRENT VALUE OF THIS SELECT
dim currentValue
currentValue = request.form(&quot;select1&quot;)

'OPEN <SELECT> TAG
response.write(&quot;<select name=select1&quot;)

'WRITE FIRST OPTION
response.write(&quot;<option value=&quot;&quot;&quot;&quot;>Select One</option>&quot;)

'GET INTO LOOP
while not rs.eof
with response
.write(&quot;<option value=&quot; & rs(&quot;value&quot;)

'CHECK CURRENT VALUE AND SELECT IT IF IT'S THE SAME
if rs(&quot;value&quot;) = currentValue then
.write(&quot; selected&quot;)
end if

.write(&quot;>&quot; & rs(&quot;text&quot;) & &quot;</option>&quot;)
end with
rs.movenext
wend

'CLOSE </SELECT> TAG
response.write(&quot;</select>&quot;)

:)
Paul Prewett
penny.gif
penny.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top