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

comma seperated list in <OPTION> 1

Status
Not open for further replies.

katherinep

Programmer
Sep 18, 2003
49
AU
Hello,

I have a field in a db which holds colours and they are seperated by commas: red,blue,green etc. The colours are needed to populate a dropdown box in a form, but split by the commas.

The page I have is in Coldfusion and I am converting it to ASP. The code in ColdFusion is

Code:
<CFIF #len(varColours)# gt 0>
  <CFLOOP list="#varColours#" delimiters="," index="idx">
    <CFOUTPUT>
      <OPTION VALUE="#idx#">#idx#</OPTION>
    </CFOUTPUT>
  </CFLOOP>
</CFIF>

Can anyone help me, ive been looking about and have found a bit of code that removes the commas:

Code:
<%
Dim strAryWords
Dim strValue

strValue = rstGetCarColour("Colours")
strAryWords = Split(strValue, ",")
' - strAryWords is now an array 
Dim i
For i = 0 to Ubound(strAryWords)
	Response.Write i & " = " & strAryWords(i) & "<BR>"
Next

%>
But now I can't get this to populate my dropdown. This is probably very easy but I have been trying to find the answer for a couple of days now with no luck,

Thanks,

Katherine
 
i'm assuming you want to know how to from the drop down, it's pretty much the same as your cold fusion script.

1 Question tho is the rstGetCarColour, I take it this is a function to get the comma delimited list from database. I have put question marks around the line.

Code:
<select name="colours">
<%
Dim strAryWords
Dim strValue

??
strValue = rstGetCarColour("Colours")
??


strAryWords = Split(strValue, ",")
' - strAryWords is now an array 
Dim i
For i = 0 to Ubound(strAryWords)
%>    
<option value="<%= strAryWords(i)%>"><%= strAryWords(i)%></option>
<%
Next
%>
</select>
 
to create a dropdown selector this bit

Code:
For i = 0 to Ubound(strAryWords)
    Response.Write i & " = " & strAryWords(i) & "<BR>"
Next

should be something like
Code:
with response
.write "<select name='name'>" & vbCrLf
For i = 0 to Ubound(strAryWords)
    .write "<option value='"
    .write strAryWords(i)
    .write "'>"
    .write strAryWords(i)
    .write "</option>" & vbCrLf
Next
.write </select>" & vbCrLf
end with



Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top