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

drop down value carry over to asp page

Status
Not open for further replies.

harpconn

Technical User
Jul 15, 2002
15
0
0
US
I have a drop down menu on page1.asp A choice from the drop down creates page2.asp (or recursively, page1.asp).

I am losing the value of the "selected" item when the new page appears.

How can I retain it? Is there some "selected" property I can set?
 
<option selected value=<%=&quot;request(&quot;previousvalue&quot;)&quot;> Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
Maybe explain that a bit better
On first page
<select name=&quot;select_box1>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>

on second page
<select name=&quot;select_box2>
<option selected value=&quot;<%=request(&quot;select_box1&quot;)%>&quot;>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select> Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
Try viewing my FAQ: faq333-3228. It might help. ________________________________________________________________________
Are you trying to debug your ASP applications? See faq333-3255 for more details

regards,
Brian
 
Thanks, Gary. Thanks Brian.

Gary's answer seems to work for 2 page situation, but I couldn't make it work for recursive where I want to have the form's action be the page on which it resides. (for example, dropdown a menu of book authors, select one, and get dynamic data for amazon for the author's books and show the dynamic data on the same page).

At the moment, my list is static, not dynamic, but I'd like to get some nice reusuable generic code to handle this situation in both recursive and page2 settings with dynamic as well as static.
Brian's code seemed to handle building a dynamic drop down, but I'm not sure exactly how it handles the carry over problem.
 
there's no reason why this wouldn't be a recursive example as long as the naming instances are used appropriatly
you can do two pages and or you can do fifty as long as you keep your naming down and accurate
On first page
<select name=&quot;select_box1>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>

on second page
<select name=&quot;select_box2>
<option selected value=&quot;<%=request(&quot;select_box1&quot;)%>&quot;>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
on thrid page
<select name=&quot;select_box3>
<option selected value=&quot;<%=request(&quot;select_box2&quot;)%>&quot;>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
on forth page
<select name=&quot;select_box4>
<option selected value=&quot;<%=request(&quot;select_box3&quot;)%>&quot;>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select> _________________________________________________________
for the best results to your questions: FAQ333-2924
[sub]01001111 01101110 01110000 01101110 01110100[/sub]
onpnt2.gif
[sup] [/sub]
 
If im reading you right, just have one page that submits to itself all the time. So the select box is always displaying the last selected value.
So...
<select name=&quot;selectbox>
<option selected value=&quot;<%=request(&quot;selectbox&quot;)%>></option>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select> Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
Gary:
Obviously, there's something I am misunderstanding about how this whole thing works. Here's brief demo code of what I'm trying to do. I keep getting the same selected menu. Maybe if you can take a look you'll be able to see what I'm doing wrong. [real code has long and complex GetAmazon(BrowseNode) function which is working fine.] My only problem is dropdown selectbox. If you don't have time or suggestions, I'll just do a workaround.

<%@Language=VBscript%>
<%Option Explicit%>


<HTML>
<script language=vbscript></script>
<HEAD>
<title>browse</title></HEAD>

<BODY>
<%
'--------------------------------------------------------
' Recursive Amazon Web Services Simple ASP Parser
'--------------------------------------------------------

'--- Option Explicit At Top Forces us to declare all variables.

'--------------------------------------------------------
Dim AssociatesID ' If you want $$$
Dim DevToken ' The token you received
Dim Catalog ' Catalog you're searching
Dim XSLURL ' Location of your XSL

AssociatesID = &quot;wildmindworkshop&quot;
DevToken = &quot;D1JBE2M3HUXKHK&quot;
Catalog = &quot;books&quot;
XSLURL = &quot;'--------------------------------------------------------

'--- Declare some things we'll work with
Dim BrowseNode, Count, x, Page

'--- Get the Page so that you can page through results!
Page = request(&quot;page&quot;)
if len(Page) = 0 then Page = 1 else Page = cint(Page)

'--- Get the BrowseNode
BrowseNode = request(&quot;browsenode&quot;)

' Random function to use for debugging
Function GiveRandom(high, low)
Randomize
GiveRandom = Int((high - low + 1) * Rnd + low)
End Function


'--------------------------------------------------------
' Search Amazon's XML Function
'--------------------------------------------------------
Function GetAmazon(BrowseNode)
' This function does the main processing in the real program
' It populates arrays from XML data downloaded from Amazon
' and parses the XML nodes

If BrowseNode=&quot;Exit&quot; Then
Count=0
Exit Function
End If
' Debug simulate increment counter for each book found in each &quot;batch&quot;
Count=GiveRandom(1,10)

response.write &quot;*** DEBUG: BrowseNode= &quot; & BrowseNode & &quot;; Count = &quot; & Count

End Function

'--------------------------------------------------------

'--- This calls the actual GetAmazon Function and populates our Arrays.
'--- BrowseNode parameter comes from dropdown menu form
GetAmazon(BrowseNode)
%>

<form method=&quot;POST&quot; action=&quot;testdropdown.asp&quot;>
<select name=&quot;browsenode&quot; >
<option selected value=&quot;<%=request(&quot;browsenode&quot;)%>></option>
<option value=&quot;1000&quot;>Top Book Node</option>
<option value=&quot;1&quot;>Art and Photography</option>
<option value=&quot;45&quot;>Bargain Books Outlet</option>
<option value=&quot;2&quot;>Biographies and Memoirs</option>
<option value=&quot;3&quot;>Business and Investing</option>
<option value=&quot;4&quot;>Children&#39;s Books</option>
<option value=&quot;Exit&quot;>Exit Debug</option>
</select>
<input type=&quot;submit&quot; value=&quot;Go&quot;></p>
</form>
<%
'--- Write out the desired book information
response.write &quot;<b> Page &quot; & Page & &quot;<BR>&quot;
For x = 1 to Count
response.write &quot;*** DEBUG: write out book info on each of up to 10 books in a batch <BR>&quot;
Next

if Count = 0 then
%>Sorry no results. Try again...
<% else
if Page > 1 then %>
[<a href=&quot;testdropdown.asp?BrowseNode=<%=BrowseNode%>&page=<%=Page-1%>&quot;>Previous</a>]
<% end if %><% if Count = 10 then %>
&nbsp;[<a href=&quot;testdropdown.asp?BrowseNode=<%=BrowseNode%>&page=<%=Page+1%>&quot;>More</a>]<% end if %><% end if %>




</BODY>

</HTML>
 
I love color coded editors ;)
Check to see if this was a cut and paste error or an error in your original code, I'll lend you the quote ;)
Code:
<option selected value=&quot;<%=request(&quot;browsenode&quot;)%>
&quot;
Code:
></option>

Also, while your setting the value of the option to what was selected on the previous page, you have not specified what the text is supposed to be. Check the source using view source and I will bet that the value is set correctly, there just isn't any text specified between the option tags for it to display (thus the empty option that appears after you have submitted it a single time).

-Tarwn [sub]01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101 [/sub]
[sup]29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19[/sup]
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
Tarwn:
Good catch on the missing quote mark! Thanks.

Great catch on what's going on. View source does indeed show it being set correctly for &quot;value&quot;, but HOW do I specify for the text that goes along with the value to SHOW?

I don't know what to use as a reference to the text.

You're the greatest! Thanks.
 
Whatever is in between the tags is the &quot;text&quot; for the option, whatever is in the &quot;value&quot; attribute is the actual value of the option.
What I would consider doing, if I were you, would be to create an ASP array of all the value/text pairs and then when you need the options print them out. This means you wouldn't need to pass the text of the option to the next page in order to display the selected one, or come up with a hard coded if-then or select case statement.

For example:
Code:
<%
'Set up an arry somewhere for all the options
'   You could even put this in an include file for easy access from other pages that need it
Dim myList(3,1)
myList(0,0) = &quot;1&quot;
myList(0,1) = &quot; Red &quot;
myList(1,0) = &quot;12&quot;
myList(1,1) = &quot; Blue &quot;
myList(2,0) = &quot;309&quot;
myList(2,1) = &quot; Green &quot;
myList(3,0) = &quot;432&quot;
myList(3,1) = &quot; Yeller &quot;

'later on when we need to output the dropdown:
%>
<select name=&quot;selColor&quot;>
   <%
   For i = 0 to UBound(myList,1)
      'Write the first part of the option tag
      Response.Write &quot;<option value='&quot; & myList(i,0) & &quot;'&quot;
      'check if it is selected
      If Request.Form(&quot;browsenode&quot;) = myList(i,0) Then Response.Write &quot; selected&quot;
      'finish off the option tags
      Response.Write &quot;>&quot; & myList(i,1) & &quot;</option>&quot;
   Next
%>
</select>


This way you can easily add new values to your list by simply making your initial array larger, you are also able to only pass the id of the selected option (browsernode) from page to page as your doing now, but the user will see the text for the selecetd node because instead of adding a new node for the selected option your simply reusing one you would have printed out anyways.

Hope this makes sense,
-Tarwn [sub]01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101 [/sub]
[sup]29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19[/sup]
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
Tarwn:
Thanks. That should do it. Perhaps I'll just break down and stick them in a DB like and create selectbox dynamically as I should have done in the first place.


Everybody... thank you. I'm OK now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top