Solved

Pass Entire Contents of Combo Box in Session in Classic asp

Posted on 2011-02-10
7
748 Views
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?
thanks
john
 1.jpg 2.jpg
search.asp:

FinancialTrackingCodes=session("FinancialTrackingCodes")
	FinancialTrackingDescription=session("FinancialTrackingDescription")
	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
		next
		Response.write "</select>"
	else
		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>"
--------------
reportsortby.asp:
	<%if session("sProgramNumber") <> "" then %>
		<INPUT type="text" name="program" value="<%response.write Replace(Replace(Trim(session("sProgramNumber")),"'",""),", ",",") %>" />
   <%end if %>

Open in new window

0
Comment
Question by:jtrapat1
  • 3
  • 3
7 Comments
 
LVL 28

Expert Comment

by:sybe
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?
0
 

Author Comment

by:jtrapat1
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?
thanks
john
0
 
LVL 19

Expert Comment

by:nschafer
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).  

Neal.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:jtrapat1
ID: 34871723
nschafer-
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.


thanks
john

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

Open in new window

0
 
LVL 19

Accepted Solution

by:
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,

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

Open in new window

0
 

Author Comment

by:jtrapat1
ID: 34876741
nschafer-
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.

thanks
again john
0
 
LVL 19

Expert Comment

by:nschafer
ID: 34878796
Glad I could help.

Neal.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

18 Experts available now in Live!

Get 1:1 Help Now