Pass Entire Contents of Combo Box in Session in Classic asp

Posted on 2011-02-10
Last Modified: 2012-06-27
I have a form which posts Search criteria to another asp page to display a Confirmation of selected values.
One of my objects is a combo box, pre-filled with the available selections from the logged on user's profile.
I have a default value of a blank OPTION tag and, if chosen, I would like to pass the rest of the list of values to the next page as comma-separated values.  
I cant get this part working.

Maybe I should use a different type of control - possibly a listbox;
Anyway, if a single selection is chosen, that value is passed to the next page and this part is working.
Attached is my code so far -
ive attached the form submit code and the small section that receives the session variable:

and a screen shot of the values passed from page to page:
I can get one value to pass correctly but how can I pass multiples with a default value of spaces?
 1.jpg 2.jpg

	firstpass =true

	if ubound(FinancialTrackingCodes)>0 then
			Response.write "<select name=""sProgramNumber"" size=1><option></option>"
		for i =1 to ubound(FinancialTrackingCodes)-1
			Response.write "<OPTION VALUE='"& FinancialTrackingCodes(i)&"'>"
								if instr(1, session("sProgramNumber"), FinancialTrackingCodes(i),1)  then response.write "'selected>"
					Response.write FinancialTrackingCodes(i) & " - " & FinancialTrackingDescription(i) & "</option>" & vbcrlf
		Response.write "</select>"
		Response.write "No Records Found"

	end if

	Response.write "<input type=hidden name=""sAgency_code"" value=""" & session("AgencyCodes")(0) & " - " & session("AgencyTitles")(0) & """>"
	Response.write "</td>"
	Response.write "</tr>"
	<%if session("sProgramNumber") <> "" then %>
		<INPUT type="text" name="program" value="<%response.write Replace(Replace(Trim(session("sProgramNumber")),"'",""),", ",",") %>" />
   <%end if %>

Open in new window

Question by:jtrapat1
  • 3
  • 3
LVL 28

Expert Comment

ID: 34870670
First of all a Session object isn't meant to pass values from one page to another. It is meant to store user-variables which are valid for the complete session. That includes all tabs and windows the user might have open simultaneously.

Passing values from one page top another can be done with the Request object (Form, Querystring).

Then I do not understand why you want to pass non-selected options in a dropdown to the next page, if you can retrieve them from the users profile. Why don't you retrieve them again from the users profile?

Author Comment

ID: 34870782
OK- Thanks
Ill try the request object;
I'll try to explain more in detail.
I cant get the syntax down to pass either: all options in the list OR a single selection.
Maybe you are right-
but I cant seem to retrieve the values again on the following page;
they are set at the initial logon page and I cant get them to display on the page.
do you know the syntax OR could i just replace the session with request?
LVL 19

Expert Comment

ID: 34871518
As Sybe stated, you could simply pull these values from the user profile again, however if you don't want to do that for some reason than you can create a hidden input with a comma delimited list of the values.  

I'm a bit confused by your code.  Is the Search.asp file the one you are trying to pass the data from?  It appears that you already have the data in an array stored in a session variable.  (Assuming we're talking about the FinancalTrackingCodes).  

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline


Author Comment

ID: 34871723
thanks for the help-
im having trouble trapping the data to display on a confirmation page: the reportsortby.asp
I dont know how to reference this on the following page.
Ideally, i would like to use this logic after the page is submitted with the search criteria:
If an FTC is selected, pass that one;
else pass the entire comma separated list of codes;
I can trap the single FTC code - but when nothing is selected - the followup page displays a blank:
so in "View Source" on the confirm page -
this is displayed:
                     <INPUT type="text" name="org2" value="01050" />
      <INPUT type="text" name="program" value="" />
      <INPUT type="text" name="category_code" value="E" />

I would like to have the codes displayed like this -
<INPUT type="text" name="program" value="'LU,SA,RP" />
where these three codes are from the initial combo box selection-
attached is my syntax which isnt doing what id like:
Its like I cant trap this array of codes at all.


<%if session("sProgramNumber") <> "" then %>
		<INPUT type="text" name="program" value="<%response.write request("sProgramNumber") %>" />
  		<INPUT type="text" name="program" value="<%response.write Replace(Replace(Trim(request("sProgramNumber")),"'",""),", ",",") %>" />
    <%end if %>

Open in new window

LVL 19

Accepted Solution

nschafer earned 500 total points
ID: 34875120
OK, I'm not sure where session("sProgramNumber") is being defined, but so long as the IF statement is working for you then the following should work.

Since you already have the Financial Tracking Codes in an array stored in a session variable we can just use the join function to turn the array into a comma delimited string.

Hope this helps,

<%if session("sProgramNumber") <> "" then %>
    <INPUT type="text" name="program" value="<%response.write request("sProgramNumber") %>" />
    <INPUT type="text" name="program" value="<%response.write join(session("FinancialTrackingCodes"),",") %>" />
<%end if %>

Open in new window


Author Comment

ID: 34876741
thanks for the tremendous help;
i know it seemed like a small problem but in going back and modifying someone elses 10 year old code- it helped greatly.

again john
LVL 19

Expert Comment

ID: 34878796
Glad I could help.


Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now