954,174 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

populating dropdown with SQL and making selection a session variable

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.

[CODE]
<%
Session ("ccrmonth")

strSQL=" select * from omonth order by omonth_id"

Set rs = conn.Execute(strSQL)
If not rs.eof then
%>

"
<%
rs.MoveNext


rs.Close
Set rs = Nothing

%>

<%

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

bevssi
Newbie Poster
8 posts since Dec 2009
Reputation Points: 10
Solved Threads: 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>
ArtistScope
Junior Poster
150 posts since Jun 2010
Reputation Points: 5
Solved Threads: 14
 

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
%>
bevssi
Newbie Poster
8 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

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

[CODE]


Please select a month<%


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

<%=rmonth%>

<%
rs1.movenext
Loop

rs1.Close
Set rs1=Nothing

%>

<%
If bmonth then


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

End If
%>

bevssi
Newbie Poster
8 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You