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

<option selected> validation 1

Status
Not open for further replies.

biddingbong

IS-IT--Management
Sep 10, 2004
67
MU
Hi, Ive got a combo listing numbers from 1 to 31. And when saving, the number selected will be saved in the database.

But I want the number that has been saved to be <selected> in the combo next time the page is launched.

I did that:
<%
Dim strDate
strDate = Request.Form("cboDate") 'cboDate is the combo
%>

<select name="cboDate" class="Combo">
<%
If Len(strDate)=0 Then
strDate="Date"
End If
%>

<option selected><%=strDate%></option>
<% For i=1 to 31 %>
<%Response.write "<option>" & i & "</option>"%>
<% Next %>
</select><font color="#FF0000"><sup>*</sup></font>

But the problem is that when a number has been saved,the combo will select that number but still, it will list all the numbers from 1 to 31, including the selected number.

Is there a way to remove that repetition.

Thanks.
 
Aye, there is. You want to get rid of the first option, use the loop, and print "selected" when you've matched the date. Replace this:
Code:
<option selected><%=strDate%></option>
<% For i=1 to 31 %>
<%Response.write "<option>" & i & "</option>"%>
<% Next %>
with this (you can remove the comments and extra blank lines)
Code:
<%
For i=1 to 31 

    'Write the first part of the tag
    Response.Write("<option")

    'If this iteration is equal to the date then
    'write " selected" in this particular tag
    If i = strDate Then Response.Write(" selected")

    'Write the rest of the tag
    Response.Write(">" & i & "</option>")
Next
%>
Does that make sense?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top