943,201 Members | Top Members by Rank

Ad:
  • ASP Discussion Thread
  • Marked Solved
  • Views: 698
  • ASP RSS
Jun 22nd, 2010
0

populating dropdown with SQL and making selection a session variable

Expand Post »
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
%>
<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
%>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bevssi is offline Offline
8 posts
since Dec 2009
Jun 24th, 2010
0
Re: populating dropdown with SQL and making selection a session variable
You may have to change the order of things for what you want...

ASP Syntax (Toggle Plain Text)
  1. <%
  2. strMonth = Request("month")
  3. Session("ccrmonth")= strMonth
  4.  
  5. strSQL = "SELECT * from oMonth Order By oMonth.omonth_id"
  6. Set rs = conn.Execute(strSQL)
  7. If not rs.eof then
  8. strMonth = rs("month")
  9. end if
  10. rs.Close
  11. Set rs = Nothing
  12. %>
  13.  
  14.  
  15. <form method="post" action=""
  16. <select name="month" size="1">
  17. <option value="">Select</option>
  18. <option value="01" <% if strMonth="01" then response.write" SELECTED" end if %>>January</option>
  19. <option value="02" <% if strMonth="02" then response.write" SELECTED" end if %>>February</option>
  20. <option value="03" <% if strMonth="03" then response.write" SELECTED" end if %>>March</option>
  21. <option value="04" <% if strMonth="04" then response.write" SELECTED" end if %>>April</option>
  22. <option value="05" <% if strMonth="05" then response.write" SELECTED" end if %>>May</option>
  23. <option value="06" <% if strMonth="06" then response.write" SELECTED" end if %>>June</option>
  24. <option value="07" <% if strMonth="07" then response.write" SELECTED" end if %>>July</option>
  25. <option value="08" <% if strMonth="08" then response.write" SELECTED" end if %>>August</option>
  26. <option value="09" <% if strMonth="09" then response.write" SELECTED" end if %>>September</option>
  27. <option value="10" <% if strMonth="10" then response.write" SELECTED" end if %>>October</option>
  28. <option value="11" <% if strMonth="11" then response.write" SELECTED" end if %>>November</option>
  29. <option value="12" <% if strMonth="12" then response.write" SELECTED" end if %>>December</option>
  30. </select>
  31. </form>
Reputation Points: 5
Solved Threads: 14
Junior Poster
ArtistScope is offline Offline
146 posts
since Jun 2010
Oct 26th, 2010
0
Re: populating dropdown with SQL and making selection a session variable
Thanks to all who replied. It took me forever, but I finally got it right!

ASP Syntax (Toggle Plain Text)
  1.  
  2. <form method="post" name="monthdrop">
  3. <select name="rmonth" onchange="document.monthdrop.submit();" size="1" >
  4. <option>Please select a month</option><%
  5.  
  6.  
  7. Set rs1 = Conn.Execute("SELECT DISTINCT omonth_id, month FROM omonth order by omonth.omonth_id")
  8.  
  9. do while Not rs1.eof
  10.  
  11. rmonth=rs1("month")
  12.  
  13.  
  14. If Request.Form("rmonth") <>"" Then
  15. Session("ccrmonth")=request.form("rmonth")
  16.  
  17. bmonth=True
  18. End If
  19. %>
  20.  
  21. <option value="<%=rmonthid%>"><%=rmonth%></option>
  22.  
  23. <%
  24. rs1.movenext
  25. Loop
  26.  
  27. rs1.Close
  28. Set rs1=Nothing
  29.  
  30. %>
  31. </select>
  32. </form>
  33. <%
  34. If bmonth then
  35.  
  36.  
  37. Response.Write(""& Session("ccrmonth") &"")
  38. Response.Write(""& rmonth &"")
  39.  
  40. End If
  41. %>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bevssi is offline Offline
8 posts
since Dec 2009
Oct 26th, 2010
0
Re: populating dropdown with SQL and making selection a session variable
Thanks to all who replied. It took me forever, but I finally got it right!

[CODE]

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

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP Forum Timeline: Accessing Virtual Directory file
Next Thread in ASP Forum Timeline: ASP Coding For Online System with SQL Server





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC