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

Sending result for drop down list

Status
Not open for further replies.

dommett

Programmer
Apr 30, 2004
33
US
I have a drop down list (in a form) made from a query to a database but when I try to use the form result in the action statement, it holds old data. See my code:

<form name="frmCategoryName" method="Post" action="businesses.asp?Category=<%=Request.Form("SelectedCategory")%>">

What category of business do you want to see? <SELECT size="1" name="SelectedCategory" onchange=frmCategoryName.submit()>
<%
Do While not rsCategories.EOF
If Request.Form("frmCategoryName") = rsCategories("CategoryName") then
Response.Write ("<option value=" & rsCategories("CategoryName") & "SELECTED>" & rsCategories("CategoryName") & "</option>")
else
Response.Write ("<option value=" & rsCategories("CategoryName") & ">" & rsCategories("CategoryName") & "</option>")
end if
rsCategories.MoveNext
Loop
rsCategories.Close
%>
</SELECT></form>


Problem is when you change your selection, the previous value of SelectedCategory gets sent in the call to businesses.asp instead of the current value. How do I make it so that the current value is sent?
 
The querystring value your adding to the address is storing the last selection and on top of that is entirely unnecessary as you never actually access it and would get the more current value from Request.Form, not Request.QueryString.
Code:
<form name="frmCategoryName" method="Post" action="businesses.asp[highlight]?Category=<%=Request.Form("SelectedCategory")%>[/highlight]">

Your if statement is checking the wrong form field (should be Request.Form("SelectedCategory") )
Code:
  If [highlight]Request.Form("frmCategoryName")[/highlight] = rsCategories("CategoryName") then

Correct those two and you should be good togo.

-T

barcode_1.gif
 
I'm sorry - I don't quite understand.

On the first point, I understand that the old data is in the SelectedCategory as it writes that line prior to the submission of the form. I don't understand what you mean when you say:

1) you never actually access it
Doesn't the onchange=frmCategoryName.submit() make it activate the action statement?

2) get the more current value from Request.Form, not Request.QueryString.
I'm confused since I'm not using QueryString. At first I thought maybe you meant them the other way around and I tried that but now I get no category in my address where before I got the last category.

I'm sorry about not getting this. I am learning asp by trial and error. Really need to get a good book I guess.
Thanks!
 
Never mind - I figured out that I needed to change the form method to "Get" instead of "Put" and use the Request.QueryString.
Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top