I need to show blank as first value
On my db, I have values from 0 to 24 and this code below populates a dropdown with those val开发者_开发技巧ues:
<%
SQLstmt = "Select PriorTries from myTable"
set TrySet = conn.Execute(SQLstmt)
%>
<select name="Tries">
<option value=""> </option>
<%
Do Until TrySet.EOF
TryID = TrySet("Tries")
If TryID = Tries Then sel = "SELECTED" Else sel = ""
%>
<OPTION Value="<%=TryID%>" <%=sel%> > <%=TrySet("Tries")%>
<%
TrySet.MoveNext
Loop
%>
</select>
Only problem is the 0 shows up as the default value.
I want blank, just like I have it on the code to be the default value.
What am I doing wrong?
Thanks in advance
<SELECT name="Tries">
<option value="" selected="selected"> </option>
<OPTION Value="0" SELECTED > 0
<OPTION Value="1" > 1
<OPTION Value="2" > 2
<OPTION Value="3" > 3
<OPTION Value="4" > 4
<OPTION Value="5" > 5
<OPTION Value="6" > 6
<OPTION Value="7" > 7
<OPTION Value="8" > 8
<OPTION Value="9" > 9
<OPTION Value="10" > 10
<OPTION Value="11" > 11
<OPTION Value="12" > 12
<OPTION Value="13" > 13
<OPTION Value="14" > 14
<OPTION Value="15" > 15
<OPTION Value="16" > 16
<OPTION Value="17" > 17
<OPTION Value="18" > 18
<OPTION Value="19" > 19
<OPTION Value="20" > 20
<OPTION Value="21" > 21
<OPTION Value="22" > 22
<OPTION Value="23" > 23
<OPTION Value="24" > 24
</SELECT>
Try:
<option value="" selected="selected"> </option>
I cannot see any definition for Tries
?
Undefined variables are equal to zero (Empty).
So, your if condition in your code returns True while TrySet("Tries")
is equal to zero (for first record) and prints SELECTED
. That's normal.
And I interested, you selected column as PriorTries
in the query but you try getting it with TrySet("Tries
") in the loop. Do you think that this is correct?
Whatever,
I think you need to try use like that:
If CStr(TryID) = CStr(Tries) Then sel = "SELECTED" Else sel = ""
Default your selected variable to -1. Because 0 is the default value, it's selected. I don't think you need selected='selected'. It's just selected like you have it with your valued options. My guess is your recordset has a count in it, which is returning zero. Maybe in your SQL script, if the value is zero, return -1 or null.
精彩评论