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!

Populating a drop down box

Status
Not open for further replies.

meeble

Programmer
Sep 24, 2002
137
0
0
GB
Hello,

I want to pull data from a database and populate a drop down box. I want each record to be between its own <option> tage. But the code I've done makes all the records appear in the one option!

Any help appreciated.

Cheers

James

<%
Dim conn
Dim RSEmps
set conn = server.createobject (&quot;adodb.connection&quot;)
conn.open &quot;triumph&quot;
set RSEmps = conn.execute (&quot;Select location from projects&quot;)
If RSEmps.EOF Then
response.write &quot;<b>There are no projects at present</b>&quot;
Else
response.write &quot;<select name='location'>&quot;
%>
<option>
<% =RSEmps(&quot;location&quot;)%></option>
<% end if
%></select><% conn.close %>
 
you'll have to do a lopp to populate the select.
syntax
<%response.write(&quot;<select name='location'>&quot;)
Do while not RSEmps.EOF
response.write(&quot;<option>&quot;)
RSEmps(&quot;location&quot;)
RSEmps.MoveNext
loop
response.write(&quot;</select>&quot;) A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
Hello,

Thanks for your help.

But all I get is the error message:

Microsoft VBScript runtime error '800a01c2'

Wrong number of arguments or invalid property assignment

The code I have now is:

<%
Dim conn
Dim RSEmps
set conn = server.createobject (&quot;adodb.connection&quot;)
conn.open &quot;triumph&quot;
set RSEmps = conn.execute (&quot;Select location from projects&quot;)
response.write(&quot;<select name='location'>&quot;)
Do while not RSEmps.EOF
response.write(&quot;<option>&quot;)
RSEmps(&quot;location&quot;)
RSEmps.MoveNext
loop
response.write(&quot;</select>&quot;) %>
<%conn.close %>
 
Code:
...
response.write(&quot;<option>&quot;)
RSEmps(&quot;location&quot;)   '<--- you need a response.write
RSEmps.MoveNext
...
it may laso be safer to put end tags on your options.
Code:
...
response.write(&quot;<option>&quot;&RSEmps(&quot;location&quot;)&&quot;</option&quot;>)   
RSEmps.MoveNext
...

-Tarwn If your happy and you know it...
 
try this
<select name=&quot;location&quot;>
<%
Dim conn, RSEmps
set conn = server.createobject (&quot;adodb.connection&quot;)
conn.open &quot;triumph&quot;
set RSEmps = conn.execute (&quot;Select location from projects&quot;)
Do While Not RSEmps.EOF
%>
<option VALUE=&quot;<%= RSEmps(&quot;location&quot;) %>&quot;>
<%
RSEmps.MoveNext
Loop
RSEmps.Close
conn.Close
%>
</option>
</select>
A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
onpnt:
You aren't printing out anything to display for those options :)
Code:
<select name=&quot;location&quot;> 
<%
Dim conn, RSEmps
set conn = server.createobject (&quot;adodb.connection&quot;)
conn.open &quot;triumph&quot;
set RSEmps = conn.execute (&quot;Select location from projects&quot;)
Do While Not RSEmps.EOF 
%>
<option VALUE=&quot;<%= RSEmps(&quot;location&quot;) %>&quot;><%= RSEmps(&quot;location&quot;) %></option>
<%
RSEmps.MoveNext
Loop
RSEmps.Close 
conn.Close
%> 
</option>
</select>
If your happy and you know it...
 
Ya I know.
hence the word syntax, I was trying to get the point across
I guess figuring the noticable shouldn't be thought

sorry about the sloppy post in that case A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
Here is a suggestion.

<SELECT name=&quot;location&quot;>
<OPTION>-Select a Location-</OPTION>
<%
Do While Not RSEmps.EOF
Response.Write &quot;<OPTION value=&quot; & RSEmps(&quot;intLocationID&quot;) & &quot;>&quot;
Response.Write RSEmps(&quot;location&quot;)
Response.Write &quot;</OPTION>&quot;
RSEmps.MoveNext
Loop

RSEmps.Close
conn.Close
Set RSEmps = Nothing
Set conn = Nothing
%>
</SELECT>


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top