0

I'm rather new to this and really need some help. I know I'm close but I just can't get this to work. My omonth table has only 2 fields, id and month. I want a drop down to lists the months and I want the selected value to become a session variable. Can you please help? It should be very simple but I've spent hours trying to get it to work.

<%
Session ("ccrmonth")

strSQL=" select * from omonth order by omonth_id"

Set rs = conn.Execute(strSQL)
    If not rs.eof then
%>
<form method="post" action="evanreports1.asp"
    <select name="month" size="1">


    <option value="<%=rs("month")%>"</option>
    <%
    rs.MoveNext


    rs.Close
    Set rs = Nothing

%>  
    </select>

</form>

<%

Session("ccrmonth")= request.form("month")
If rs(ccrmonth)<>"" Then
response.write "& ccrmonth &"
End If
%>

Edited by Reverend Jim: Fixed formatting

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by bevssi
0

You may have to change the order of things for what you want...

<%
strMonth = Request("month")
Session("ccrmonth")= strMonth

strSQL = "SELECT * from oMonth Order By oMonth.omonth_id"
Set rs = conn.Execute(strSQL)
	If not rs.eof then
		strMonth = rs("month")
	end if
	rs.Close
Set rs = Nothing
%>


<form method="post" action=""
	<select name="month" size="1">
                <option value="">Select</option>
                <option value="01" <% if strMonth="01" then response.write" SELECTED" end if %>>January</option>
                <option value="02" <% if strMonth="02" then response.write" SELECTED" end if %>>February</option>
                <option value="03" <% if strMonth="03" then response.write" SELECTED" end if %>>March</option>
                <option value="04" <% if strMonth="04" then response.write" SELECTED" end if %>>April</option>
                <option value="05" <% if strMonth="05" then response.write" SELECTED" end if %>>May</option>
                <option value="06" <% if strMonth="06" then response.write" SELECTED" end if %>>June</option>
                <option value="07" <% if strMonth="07" then response.write" SELECTED" end if %>>July</option>
                <option value="08" <% if strMonth="08" then response.write" SELECTED" end if %>>August</option>
                <option value="09" <% if strMonth="09" then response.write" SELECTED" end if %>>September</option>
                <option value="10" <% if strMonth="10" then response.write" SELECTED" end if %>>October</option>
                <option value="11" <% if strMonth="11" then response.write" SELECTED" end if %>>November</option>
                <option value="12" <% if strMonth="12" then response.write" SELECTED" end if %>>December</option>
	</select>
</form>
0

Thanks to all who replied. It took me forever, but I finally got it right!

<form method="post"  name="monthdrop">
<select name="rmonth" onchange="document.monthdrop.submit();" size="1" >
<option>Please select a month</option><%


Set rs1 = Conn.Execute("SELECT DISTINCT omonth_id, month FROM omonth order by omonth.omonth_id")

do while Not rs1.eof

rmonth=rs1("month")


If Request.Form("rmonth") <>"" Then
Session("ccrmonth")=request.form("rmonth")

bmonth=True
End If
%>

<option value="<%=rmonthid%>"><%=rmonth%></option>

<%
rs1.movenext
Loop

rs1.Close
Set rs1=Nothing

%>
</select>
</form>
<%
If bmonth then


Response.Write(""& Session("ccrmonth") &"")
Response.Write(""& rmonth &"")

End If
%>
0

Thanks to all who replied. It took me forever, but I finally got it right!

<form method="post"  name="monthdrop">
<select name="rmonth" onchange="document.monthdrop.submit();" size="1" >
<option>Please select a month</option><%


Set rs1 = Conn.Execute("SELECT DISTINCT omonth_id, month FROM omonth order by omonth.omonth_id")

do while Not rs1.eof

rmonth=rs1("month")


If Request.Form("rmonth") <>"" Then
Session("ccrmonth")=request.form("rmonth")

bmonth=True
End If
%>

<option value="<%=rmonthid%>"><%=rmonth%></option>

<%
rs1.movenext
Loop

rs1.Close
Set rs1=Nothing

%>
</select>
</form>
<%
If bmonth then


Response.Write(""& Session("ccrmonth") &"")
Response.Write(""& rmonth &"")

End If
%>

Edited by Reverend Jim: Fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.