Friday, September 25, 2009

Poor Mans Nested Array Splitting

Some will laugh.  Some will scoff.  Some will snort and then realize they accidentally blew a booger on their shirt and say “oh damn”.  Oh well, here goes…

<%
Const myList = "1=RED,2=YELLOW,3=GREEN,4=CYAN,5=BLUE,6=MAGENTA"

Sub ColorNumList(default)
For each pair in Split(myList, ",")
x = Split(pair, "=")
If Cstr(default) = x(0) Then
Response.Write "<option value=" & x(0) & _
" selected>" & x(1) & "</option>"
Else
Response.Write "<option value=" & x(0) & _
">" & x(1) & "</option>"
End If
Next
End Sub
%>

To use this, you simply insert it within a matching set of ASP code tags inside of a <select></select> form object tag set:

...
<select name="colornum" size="1">
<% ColorNumList 3 %>
</select>
...

No comments:

Post a Comment