Print Page | Close Window

Dropdown box problems

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=14029
Printed Date: 30 March 2026 at 3:02pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Dropdown box problems
Posted By: ub3rl337ch3ch
Subject: Dropdown box problems
Date Posted: 27 February 2005 at 9:44pm

I'm attempting a login script where the available user names are automatically populated in a dropdown box from an sql database.

 

I have used

Set vrec = Server.CreateObject("ADODB.Recordset")
sql = "SELECT CBroker.BrokerOpName FROM CBroker"
vrec.Open sql, adoCon, adLockOptimistic
WHILE NOT vrec.EOF
Response.write "{option name=Vbrok value=" & vrec("BrokerOpName") & ">" & vrec("BrokerOpName") & "{/option>"
vrec.MoveNext
WEND
vrec.Close
 
in between my select and /select tags. The dropdown box displays fine, but if you attempt to post a username which contains a space, it will only post whatever is before the first space, and nothing after. I know that a dropdown box which is hard coded will submit spaced words properly. Does anyone know what i've done wrong?



Replies:
Posted By: MadDog
Date Posted: 27 February 2005 at 9:56pm
Response.write "<option name=Vbrok value=""" & vrec("BrokerOpName") & """>" & vrec("BrokerOpName") & "</option>"

-------------
http://www.iportalx.net" rel="nofollow">


Posted By: ub3rl337ch3ch
Date Posted: 27 February 2005 at 10:05pm
cheers... i just worked out a different way, but similar... using '" & blah & "' instead of """ & blah & """
 
Is there going to be any problems you can see using the former as opposed to the latter?


Posted By: bootcom
Date Posted: 27 February 2005 at 10:07pm

Is the full name appearing in the source code ???



Posted By: bootcom
Date Posted: 27 February 2005 at 10:14pm

I don't know whether this is any use to you matey, but I didn't know anyone used wend any more. Why couldn't you just write it out like this ?? Implementing ASP into the HTML is always easier, and takes less time cos you aint processing all of the response.write stuff

Set vrec = Server.CreateObject("ADODB.Recordset")
sql = "SELECT CBroker.BrokerOpName FROM CBroker"
vrec.Open sql, adoCon, adLockOptimistic
Do WHILE NOT vrec.EOF
%>
 
<option name=Vbrok value="<%= vrec("BrokerOpName") %>"><%= vrec("BrokerOpName") %></option>
 
<%
vrec.MoveNext
loop
 
vrec.Close


Posted By: ub3rl337ch3ch
Date Posted: 27 February 2005 at 10:39pm
*feels stupid*
 
I took to writing it all into the asp because the first time i tried looping html it didn't work, obviously (now) because i had a bug somewhere. I used that as a workaround, and have since used looped html, so i probably should have gone back and changed that... but my brain disconnected on that.
 
I suppose i've just used WEND there because i was browsing the web and found it (as opposed to loop) used in an open source eg of an auto populate dropdown
is there actually any any functional difference between the two? like does WEND have bugs that loop doesn't? or is it an ease-of-reading format thing like capitalising If's and End If's?


Posted By: bootcom
Date Posted: 27 February 2005 at 11:01pm

To be fair, I have never noticed any functional difference between the 2 either but I was talking to one of the guys at the 4guysfromrolla website and he just said that I should stop using WEND as LOOP and DO are now the proper practise, I think WEND was used in the first ASP versions and it's been changed to LOOP although WEND is supported through all versions of ASP. To me it is an ease of use thing (like you say to make it easier to read) although I hardly even use that any more. If your pulling from an access database thats packed, any timesaver is a help so for that I use Arrays.

Instead of:

Set vrec = Server.CreateObject("ADODB.Recordset")
sql = "SELECT CBroker.BrokerOpName FROM CBroker"
vrec.Open sql, adoCon, adLockOptimistic
Do WHILE NOT vrec.EOF
%>
 
<option name=Vbrok value="<%= vrec("BrokerOpName") %>"><%= vrec("BrokerOpName") %></option>
 
<%
vrec.MoveNext
loop
 
vrec.Close
'and set to nothing
set vrec = nothing
%>
 
I just use the following. If your wondering what the 1 relates to in vrecArray(1, x) , this is the 2nd column in your database table (the first - primary key generally is 0,x) The x = 0 to uBound(vrecArray, 2) loops from the first to last record.
 
<%
vrec.Open sql, adoCon, adLockOptimistic
 
' If your database is empty then do something
If vrec.eof then
%>
There are no user's currently in the database
<%
Else
vrecArray = vrec.getRows()
' now loop through your array
For x = 0 to uBound(vrecArray, 2)
%>
<option value="<%= vrecArray(1, x) %>"><%= vrecArray(1, x) %></option>
<%
Next
' close the recordset and reset to nothing
vrec.close
set vrec = nothing
%>


Posted By: ub3rl337ch3ch
Date Posted: 27 February 2005 at 11:25pm
ok thanks.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net