trouble with session variable

C

Chuck

I'm trying to accomplish 2 things: store a user's select-
box response from a form in a session variable and then
repopulate that selection on the user's next call to the
form (following post action) so they don't have to
reselect it. How???

Thanks!
 
K

Kevin Spencer

You need to back up a bit. Apparently, you have an ASP form which posts back
to itself. You want a drop-down list box (HTML select object) to retain its
value when the form is reloaded. Am I following you so far? If so, good.
Note that nothing in the requirement says anything about using Session. We
need to separate out the business requirement from the solution. The next
step is to determine the solution that best fulfills the requirement.
Session State is a medium for persisting data across pages in an ASP
application. However, this page is posting its data back to itself. That is,
when the form posts, it posts to itself, and the code in the same page that
receives the HTTP request with all the form data in it is the same page that
will render the HTML that is sent back to the browser. In other words, what
good would Session State do? The page doesn't need to store the value of the
select object. It needs to RE-store the value, which was posted with the
form data.

The value from the select object will be in the Request.Form Collection.
When the Request is received, it's a simple matter to create a JavaScript
that sets the selectedIndex of the select object:

<%Dim selectedValue
selectedValue = Request.Form("selectName")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms[0].selectName.options.length; i++)
{
if (document.forms[0].selectName.options.value ==
"<%=selectedValue%>")
{
document.forms[0].selectName.selectedIndex = i;
break;
}
}
// --></script>

Of course, if you have some OTHER reason for wanting to store the value in
Session, that's easy:

<%Session("selectedValue") = selectedValue%>

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
 
C

Chuck

Haven't tried this yet, Kevin, but it makes great sense.
I'll give it a try today. THANKS!!!

Chuck
-----Original Message-----
You need to back up a bit. Apparently, you have an ASP form which posts back
to itself. You want a drop-down list box (HTML select object) to retain its
value when the form is reloaded. Am I following you so far? If so, good.
Note that nothing in the requirement says anything about using Session. We
need to separate out the business requirement from the solution. The next
step is to determine the solution that best fulfills the requirement.
Session State is a medium for persisting data across pages in an ASP
application. However, this page is posting its data back to itself. That is,
when the form posts, it posts to itself, and the code in the same page that
receives the HTTP request with all the form data in it is the same page that
will render the HTML that is sent back to the browser. In other words, what
good would Session State do? The page doesn't need to store the value of the
select object. It needs to RE-store the value, which was posted with the
form data.

The value from the select object will be in the Request.Form Collection.
When the Request is received, it's a simple matter to create a JavaScript
that sets the selectedIndex of the select object:

<%Dim selectedValue
selectedValue = Request.Form("selectName")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].selectName.options .value ==
"<%=selectedValue%>")
{
document.forms[0].selectName.selectedIndex = i;
break;
}
}
// --></script>

Of course, if you have some OTHER reason for wanting to store the value in
Session, that's easy:

<%Session("selectedValue") = selectedValue%>

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

I'm trying to accomplish 2 things: store a user's select-
box response from a form in a session variable and then
repopulate that selection on the user's next call to the
form (following post action) so they don't have to
reselect it. How???

Thanks!


.
 
C

Chuck

Hmm. Obviously I coded it wrong. The select field name
is "Center." Here's what I entered, and it gives me an
error stating "Error: 'document.forms.0.Center' is null
or not an object" Code: 0

Code I used:
<%Dim selectedValue
selectedValue = Request.Form("Center")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].Center.options.value =="<%
=selectedValue%>")
{
document.forms[0].Center.selectedIndex = i;
break;
}
}
// --></script>

What did I foul up?

Thanks.

Chuck
-----Original Message-----

<%Dim selectedValue
selectedValue = Request.Form("selectName")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].selectName.options .value ==
"<%=selectedValue%>")
{
document.forms[0].selectName.selectedIndex = i;
break;
}
}
// --></script>

Of course, if you have some OTHER reason for wanting to store the value in
Session, that's easy:

<%Session("selectedValue") = selectedValue%>

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

I'm trying to accomplish 2 things: store a user's select-
box response from a form in a session variable and then
repopulate that selection on the user's next call to the
form (following post action) so they don't have to
reselect it. How???

Thanks!


.
 
K

Kevin Spencer

You have a couple of alternatives. One is that there is more than one form
on the page. Another is that the form field exists outside of the form.
Another is that the name of the select object isn't "Center."

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

Chuck said:
Hmm. Obviously I coded it wrong. The select field name
is "Center." Here's what I entered, and it gives me an
error stating "Error: 'document.forms.0.Center' is null
or not an object" Code: 0

Code I used:
<%Dim selectedValue
selectedValue = Request.Form("Center")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].Center.options.value =="<%
=selectedValue%>")
{
document.forms[0].Center.selectedIndex = i;
break;
}
}
// --></script>

What did I foul up?

Thanks.

Chuck
-----Original Message-----

<%Dim selectedValue
selectedValue = Request.Form("selectName")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].selectName.options .value ==
"<%=selectedValue%>")
{
document.forms[0].selectName.selectedIndex = i;
break;
}
}
// --></script>

Of course, if you have some OTHER reason for wanting to store the value in
Session, that's easy:

<%Session("selectedValue") = selectedValue%>

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

I'm trying to accomplish 2 things: store a user's select-
box response from a form in a session variable and then
repopulate that selection on the user's next call to the
form (following post action) so they don't have to
reselect it. How???

Thanks!


.
 
C

Chuck

The first one was right- more than 1 form on the page.
So how do I correctly reference the right form,
called "FrontPage_Form1"? As form(1)?
Or as form("FrontPage_Form1")?

Thanks.

Chuck
-----Original Message-----
You have a couple of alternatives. One is that there is more than one form
on the page. Another is that the form field exists outside of the form.
Another is that the name of the select object isn't "Center."

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

Hmm. Obviously I coded it wrong. The select field name
is "Center." Here's what I entered, and it gives me an
error stating "Error: 'document.forms.0.Center' is null
or not an object" Code: 0

Code I used:
<%Dim selectedValue
selectedValue = Request.Form("Center")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].Center.options.value =="<%
=selectedValue%>")
{
document.forms[0].Center.selectedIndex = i;
break;
}
}
// --></script>

What did I foul up?

Thanks.

Chuck
-----Original Message-----

<%Dim selectedValue
selectedValue = Request.Form("selectName")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].selectName.options .value ==
"<%=selectedValue%>")
{
document.forms
[0].selectName.selectedIndex =
i;
break;
}
}
// --></script>

Of course, if you have some OTHER reason for wanting
to
store the value in
Session, that's easy:

<%Session("selectedValue") = selectedValue%>

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

I'm trying to accomplish 2 things: store a user's select-
box response from a form in a session variable and then
repopulate that selection on the user's next call to the
form (following post action) so they don't have to
reselect it. How???

Thanks!


.



.
 
K

Kevin Spencer

Forms in an HTML document are in an array. The number is the index of the
array. If it is the second form on the page, refer to it as
document.forms[1]; There are other ways to reference it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

Chuck said:
The first one was right- more than 1 form on the page.
So how do I correctly reference the right form,
called "FrontPage_Form1"? As form(1)?
Or as form("FrontPage_Form1")?

Thanks.

Chuck
-----Original Message-----
You have a couple of alternatives. One is that there is more than one form
on the page. Another is that the form field exists outside of the form.
Another is that the name of the select object isn't "Center."

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

Hmm. Obviously I coded it wrong. The select field name
is "Center." Here's what I entered, and it gives me an
error stating "Error: 'document.forms.0.Center' is null
or not an object" Code: 0

Code I used:
<%Dim selectedValue
selectedValue = Request.Form("Center")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].Center.options.value =="<%
=selectedValue%>")
{
document.forms[0].Center.selectedIndex = i;
break;
}
}
// --></script>

What did I foul up?

Thanks.

Chuck

-----Original Message-----

<%Dim selectedValue
selectedValue = Request.Form("selectName")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].selectName.options
.value ==
"<%=selectedValue%>")
{
document.forms [0].selectName.selectedIndex =
i;
break;
}
}
// --></script>

Of course, if you have some OTHER reason for wanting to
store the value in
Session, that's easy:

<%Session("selectedValue") = selectedValue%>

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

message
I'm trying to accomplish 2 things: store a user's
select-
box response from a form in a session variable and then
repopulate that selection on the user's next call to
the
form (following post action) so they don't have to
reselect it. How???

Thanks!


.



.
 
C

Chuck

Nope, 0 was the right number- it's the first form. But
in loading the variable I still have selectedValue =
Request.Form("Center")
No reference to which form. Should the form be
referenced, and if so, how?

Thanks for helping me with this.

Chuck
-----Original Message-----
Forms in an HTML document are in an array. The number is the index of the
array. If it is the second form on the page, refer to it as
document.forms[1]; There are other ways to reference it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

The first one was right- more than 1 form on the page.
So how do I correctly reference the right form,
called "FrontPage_Form1"? As form(1)?
Or as form("FrontPage_Form1")?

Thanks.

Chuck
-----Original Message-----
You have a couple of alternatives. One is that there
is
more than one form
on the page. Another is that the form field exists outside of the form.
Another is that the name of the select object isn't "Center."

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

Hmm. Obviously I coded it wrong. The select field name
is "Center." Here's what I entered, and it gives me an
error stating "Error: 'document.forms.0.Center' is null
or not an object" Code: 0

Code I used:
<%Dim selectedValue
selectedValue = Request.Form("Center")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].Center.options.value =="<%
=selectedValue%>")
{
document.forms[0].Center.selectedIndex = i;
break;
}
}
// --></script>

What did I foul up?

Thanks.

Chuck

-----Original Message-----

<%Dim selectedValue
selectedValue = Request.Form("selectName")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].selectName.options
.value ==
"<%=selectedValue%>")
{
document.forms [0].selectName.selectedIndex =
i;
break;
}
}
// --></script>

Of course, if you have some OTHER reason for
wanting
to
store the value in
Session, that's easy:

<%Session("selectedValue") = selectedValue%>

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

message
I'm trying to accomplish 2 things: store a user's
select-
box response from a form in a session variable
and
then
repopulate that selection on the user's next call to
the
form (following post action) so they don't have to
reselect it. How???

Thanks!


.



.



.
 
K

Kevin Spencer

The only form data in the Request.Form Collection will be from the form
which posted.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

Chuck said:
Nope, 0 was the right number- it's the first form. But
in loading the variable I still have selectedValue =
Request.Form("Center")
No reference to which form. Should the form be
referenced, and if so, how?

Thanks for helping me with this.

Chuck
-----Original Message-----
Forms in an HTML document are in an array. The number is the index of the
array. If it is the second form on the page, refer to it as
document.forms[1]; There are other ways to reference it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

The first one was right- more than 1 form on the page.
So how do I correctly reference the right form,
called "FrontPage_Form1"? As form(1)?
Or as form("FrontPage_Form1")?

Thanks.

Chuck

-----Original Message-----
You have a couple of alternatives. One is that there is
more than one form
on the page. Another is that the form field exists
outside of the form.
Another is that the name of the select object
isn't "Center."

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

message
Hmm. Obviously I coded it wrong. The select field
name
is "Center." Here's what I entered, and it gives me an
error stating "Error: 'document.forms.0.Center' is null
or not an object" Code: 0

Code I used:
<%Dim selectedValue
selectedValue = Request.Form("Center")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].Center.options.value =="<%
=selectedValue%>")
{
document.forms[0].Center.selectedIndex = i;
break;
}
}
// --></script>

What did I foul up?

Thanks.

Chuck

-----Original Message-----

<%Dim selectedValue
selectedValue = Request.Form("selectName")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].selectName.options
.value ==
"<%=selectedValue%>")
{
document.forms
[0].selectName.selectedIndex =
i;
break;
}
}
// --></script>

Of course, if you have some OTHER reason for wanting
to
store the value in
Session, that's easy:

<%Session("selectedValue") = selectedValue%>

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

message
I'm trying to accomplish 2 things: store a user's
select-
box response from a form in a session variable and
then
repopulate that selection on the user's next call to
the
form (following post action) so they don't have to
reselect it. How???

Thanks!


.



.



.
 
C

Chuck

I follow you, but it doesn't work as written. Obviously
I'm leaving something out. Error message is still
telling me this thing about how 'document.forms.0.Center'
(with Center being the Select box name) is null or not an
object. To me that says the variable isn't being stored
successfully for retrieval on return to the page, or
there's something wrong with how the select box is
referenced. The name is okay- what else might I be
overlooking? I've got both your Java and VBScript in the
code. Is that a problem?

Chuck
-----Original Message-----
The only form data in the Request.Form Collection will be from the form
which posted.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

Nope, 0 was the right number- it's the first form. But
in loading the variable I still have selectedValue =
Request.Form("Center")
No reference to which form. Should the form be
referenced, and if so, how?

Thanks for helping me with this.

Chuck
-----Original Message-----
Forms in an HTML document are in an array. The number
is
the index of the
array. If it is the second form on the page, refer to
it
as
document.forms[1]; There are other ways to reference it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

The first one was right- more than 1 form on the page.
So how do I correctly reference the right form,
called "FrontPage_Form1"? As form(1)?
Or as form("FrontPage_Form1")?

Thanks.

Chuck

-----Original Message-----
You have a couple of alternatives. One is that
there
is
more than one form
on the page. Another is that the form field exists
outside of the form.
Another is that the name of the select object
isn't "Center."

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

message
Hmm. Obviously I coded it wrong. The select field
name
is "Center." Here's what I entered, and it gives me an
error stating "Error: 'document.forms.0.Center'
is
null
or not an object" Code: 0

Code I used:
<%Dim selectedValue
selectedValue = Request.Form("Center")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].Center.options.value =="<%
=selectedValue%>")
{
document.forms[0].Center.selectedIndex = i;
break;
}
}
// --></script>

What did I foul up?

Thanks.

Chuck

-----Original Message-----

<%Dim selectedValue
selectedValue = Request.Form("selectName")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].selectName.options
.value ==
"<%=selectedValue%>")
{
document.forms
[0].selectName.selectedIndex =
i;
break;
}
}
// --></script>

Of course, if you have some OTHER reason for wanting
to
store the value in
Session, that's easy:

<%Session("selectedValue") = selectedValue%>

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

message
I'm trying to accomplish 2 things: store a user's
select-
box response from a form in a session variable and
then
repopulate that selection on the user's next call to
the
form (following post action) so they don't
have
to
reselect it. How???

Thanks!


.



.



.



.
 
K

Kevin Spencer

Post a URL or the code, and we can help you fix it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

Chuck said:
I follow you, but it doesn't work as written. Obviously
I'm leaving something out. Error message is still
telling me this thing about how 'document.forms.0.Center'
(with Center being the Select box name) is null or not an
object. To me that says the variable isn't being stored
successfully for retrieval on return to the page, or
there's something wrong with how the select box is
referenced. The name is okay- what else might I be
overlooking? I've got both your Java and VBScript in the
code. Is that a problem?

Chuck
-----Original Message-----
The only form data in the Request.Form Collection will be from the form
which posted.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

Nope, 0 was the right number- it's the first form. But
in loading the variable I still have selectedValue =
Request.Form("Center")
No reference to which form. Should the form be
referenced, and if so, how?

Thanks for helping me with this.

Chuck

-----Original Message-----
Forms in an HTML document are in an array. The number is
the index of the
array. If it is the second form on the page, refer to it
as
document.forms[1]; There are other ways to reference it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

message
The first one was right- more than 1 form on the page.
So how do I correctly reference the right form,
called "FrontPage_Form1"? As form(1)?
Or as form("FrontPage_Form1")?

Thanks.

Chuck

-----Original Message-----
You have a couple of alternatives. One is that there
is
more than one form
on the page. Another is that the form field exists
outside of the form.
Another is that the name of the select object
isn't "Center."

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

message
Hmm. Obviously I coded it wrong. The select field
name
is "Center." Here's what I entered, and it gives
me an
error stating "Error: 'document.forms.0.Center' is
null
or not an object" Code: 0

Code I used:
<%Dim selectedValue
selectedValue = Request.Form("Center")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].Center.options.value
=="<%
=selectedValue%>")
{
document.forms[0].Center.selectedIndex = i;
break;
}
}
// --></script>

What did I foul up?

Thanks.

Chuck

-----Original Message-----

<%Dim selectedValue
selectedValue = Request.Form("selectName")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].selectName.options
.value ==
"<%=selectedValue%>")
{
document.forms
[0].selectName.selectedIndex =
i;
break;
}
}
// --></script>

Of course, if you have some OTHER reason for
wanting
to
store the value in
Session, that's easy:

<%Session("selectedValue") = selectedValue%>

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Chuck" <[email protected]>
wrote in
message
I'm trying to accomplish 2 things: store a user's
select-
box response from a form in a session variable
and
then
repopulate that selection on the user's next
call to
the
form (following post action) so they don't have
to
reselect it. How???

Thanks!


.



.



.



.
 
C

Chuck \(last question!\)

Okay, I still don't know the answer, but I now know the
question. How do I alter the code you provided to loop
through not indexes but values? I wrote the select box
to store values, as in:
<option value="Bloomburg">Bloomburg</option>
I don't think it could find a match in the list when
looking for the stored index. So how do I loop through
values rather than indexes?

Thanks!! I think this is the last question!!

Chuck
-----Original Message-----
The only form data in the Request.Form Collection will be from the form
which posted.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

Nope, 0 was the right number- it's the first form. But
in loading the variable I still have selectedValue =
Request.Form("Center")
No reference to which form. Should the form be
referenced, and if so, how?

Thanks for helping me with this.

Chuck
-----Original Message-----
Forms in an HTML document are in an array. The number
is
the index of the
array. If it is the second form on the page, refer to
it
as
document.forms[1]; There are other ways to reference it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

The first one was right- more than 1 form on the page.
So how do I correctly reference the right form,
called "FrontPage_Form1"? As form(1)?
Or as form("FrontPage_Form1")?

Thanks.

Chuck

-----Original Message-----
You have a couple of alternatives. One is that
there
is
more than one form
on the page. Another is that the form field exists
outside of the form.
Another is that the name of the select object
isn't "Center."

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

message
Hmm. Obviously I coded it wrong. The select field
name
is "Center." Here's what I entered, and it gives me an
error stating "Error: 'document.forms.0.Center'
is
null
or not an object" Code: 0

Code I used:
<%Dim selectedValue
selectedValue = Request.Form("Center")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].Center.options.value =="<%
=selectedValue%>")
{
document.forms[0].Center.selectedIndex = i;
break;
}
}
// --></script>

What did I foul up?

Thanks.

Chuck

-----Original Message-----

<%Dim selectedValue
selectedValue = Request.Form("selectName")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].selectName.options
.value ==
"<%=selectedValue%>")
{
document.forms
[0].selectName.selectedIndex =
i;
break;
}
}
// --></script>

Of course, if you have some OTHER reason for wanting
to
store the value in
Session, that's easy:

<%Session("selectedValue") = selectedValue%>

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

message
I'm trying to accomplish 2 things: store a user's
select-
box response from a form in a session variable and
then
repopulate that selection on the user's next call to
the
form (following post action) so they don't
have
to
reselect it. How???

Thanks!


.



.



.



.
 
K

Kevin Spencer

Hi Chuck,

Request.Form("SelectName") is the value of the selected option, not the
selectedIndex of the select object.

The way you alter the code I provided is to understand it, and then
implement it. That's all I can give you in good conscience. I'm a "feed a
man to fish" type of guy. I have given you all of the principles involved,
including how to get the value from the Request object, how HTML forms work,
and a sample of code that creates a dynamic JavaScript function. Once you
understand it, you will be able to (1) implement your own solution, and (2)
have greater knowledge and skill under your belt, to help you with solving
future problems. If I simply wrote code for you, you would not have number
2, which is the most important of the 2. This problem will go away, but
there will always be problems to take its place.

Here is another tip on debugging ASP. You can use Response.Write to debug
your code, by writing out values to the page. When you're done debugging,
remove the debugging Response.Write statements. For example, if you want to
see what the value of Request.Form("Center") is, write it out to the page:

Response.Write(Request.Form("Center"))

Hang in there! You're making great progress!

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

Chuck (last question!) said:
Okay, I still don't know the answer, but I now know the
question. How do I alter the code you provided to loop
through not indexes but values? I wrote the select box
to store values, as in:
<option value="Bloomburg">Bloomburg</option>
I don't think it could find a match in the list when
looking for the stored index. So how do I loop through
values rather than indexes?

Thanks!! I think this is the last question!!

Chuck
-----Original Message-----
The only form data in the Request.Form Collection will be from the form
which posted.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

Nope, 0 was the right number- it's the first form. But
in loading the variable I still have selectedValue =
Request.Form("Center")
No reference to which form. Should the form be
referenced, and if so, how?

Thanks for helping me with this.

Chuck

-----Original Message-----
Forms in an HTML document are in an array. The number is
the index of the
array. If it is the second form on the page, refer to it
as
document.forms[1]; There are other ways to reference it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

message
The first one was right- more than 1 form on the page.
So how do I correctly reference the right form,
called "FrontPage_Form1"? As form(1)?
Or as form("FrontPage_Form1")?

Thanks.

Chuck

-----Original Message-----
You have a couple of alternatives. One is that there
is
more than one form
on the page. Another is that the form field exists
outside of the form.
Another is that the name of the select object
isn't "Center."

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

message
Hmm. Obviously I coded it wrong. The select field
name
is "Center." Here's what I entered, and it gives
me an
error stating "Error: 'document.forms.0.Center' is
null
or not an object" Code: 0

Code I used:
<%Dim selectedValue
selectedValue = Request.Form("Center")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].Center.options.value
=="<%
=selectedValue%>")
{
document.forms[0].Center.selectedIndex = i;
break;
}
}
// --></script>

What did I foul up?

Thanks.

Chuck

-----Original Message-----

<%Dim selectedValue
selectedValue = Request.Form("selectName")%>

<script type="text/javascript"><!--
for (var i = 0; i < document.forms
[0].selectName.options.length; i++)
{
if (document.forms[0].selectName.options
.value ==
"<%=selectedValue%>")
{
document.forms
[0].selectName.selectedIndex =
i;
break;
}
}
// --></script>

Of course, if you have some OTHER reason for
wanting
to
store the value in
Session, that's easy:

<%Session("selectedValue") = selectedValue%>

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Chuck" <[email protected]>
wrote in
message
I'm trying to accomplish 2 things: store a user's
select-
box response from a form in a session variable
and
then
repopulate that selection on the user's next
call to
the
form (following post action) so they don't have
to
reselect it. How???

Thanks!


.



.



.



.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top