Showing posts with label listbox. Show all posts
Showing posts with label listbox. Show all posts

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>
...

Tuesday, July 7, 2009

ASP - Generate Alphabet List


<select name="letter" size="1">
<%
For i = Asc("A") to Asc("Z")
Response.Write "<option>" & Chr(i) & "</option>"
Next
%>
</select>

Friday, July 3, 2009

ASP ListBox for U.S. State Abbreviations


Sub StatesList(default)
Dim lst, x
lst = "AL,AK,AZ,AR,CA,CO,CT,DE,DC,FL," & _
"GA,HI,ID,IL,IN,IA,KS,KY,LA,ME," & _
"MD,MA,MI,MN,MS,MO,MT,NE,NV,NH," & _
"NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI," & _
"SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY"

If default = "" Then
Response.Write "" & vbCRLF
End If

For each x in Split(lst, ",")
If Ucase(x) = Ucase(default) Then
Response.Write "" & vbCRLF
Else
Response.Write "" & vbCRLF
End If
Next
End Sub


Example:

<select name="state" size="1">
<% StatesList "VA" %>
</select>