467,885 Members | 1,355 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,885 developers. It's quick & easy.

Setting option value to session var

Hello,

I thought this should be easy, but... all I want to do is set the value
of this state drop-down based on a session var I'm getting back from a
redirect (from the processing page):
<%
tax = session("Tax")
city = session("City")
state = session("State")
%>

<select name="state">
<option value="">--Select--</option>
<option value="AL">AL</option>
<option value="AK">AK</option>
<option value="AZ">AZ</option>
<option value="AR">AR</option>
<option value="CA">CA</option>...
</select>

I can do it with the city field easy enough like this:
City : <input type="text" name="city" value="<%=city%>" size="8"
maxlength="15">

But this same technique doesn't work for the select box, it just keeps
returning to the
"--Select--".

Also, I'm trying to clear the fields that are populated with values
from the session vars like so:

<input type="Button" name="Reset" value="Clear"
onClick="clearFields();">

function clearFields()
{
document.form1.state.value == "--Select--";
document.form1.city.value == "test";
document.form1.tax.value == "";
}

But this doesn't work. Is there something special I'm supposed to do to
be able to clear session vars out of the form? I have the following
declared at the top of the page which I thougth should work: <%
Response.Expires = 0 %>

Any help greatly appreciated.

Thanks in advance,
KP

Mar 17 '06 #1
  • viewed: 2166
Share:
6 Replies
Kermit Piper wrote on 18 mrt 2006 in
microsoft.public.inetserver.asp.general:
Hello,

I thought this should be easy, but... all I want to do is set the value
of this state drop-down based on a session var I'm getting back from a
redirect (from the processing page):
<%
tax = session("Tax")
city = session("City")
state = session("State")
if state="AL" then AL=" selected"
if state="AZ" then AZ=" selected"
etc
%>

<select name="state">
<option value="">--Select--</option>
<option value="AL">AL</option>
<option value="AL" <%=AL%>>AL</option>
<option value="AK">AK</option>
<option value="AZ" <%=AZ%>>AZ</option>
<option value="AZ">AZ</option>
etc

[I usually do this in a ASP 2 loops, having the states in a array]
<option value="AR">AR</option>
<option value="CA">CA</option>...
</select>


===========================

This is nice too, coloring the selected background serverside:

if state="AL" then AL=" selected style='background-color:yellow;'"
if state="AZ" then AZ=" selected style='background-color:yellow;'"
etc

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 18 '06 #2
Thank you Evertjan! I'll give it a try. How about clearing the form
field values, any ideas on that?

Mar 18 '06 #3
Kermit Piper wrote on 18 mrt 2006 in
microsoft.public.inetserver.asp.general:
Thank you Evertjan! I'll give it a try. How about clearing the form
field values, any ideas on that?


This is usenet, not email.
Please quote where you are responding on.

"form field values" are a clientside concept,
where ASP does not know about.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 18 '06 #4
Well that was condescending, useless and less than technically correct, all
at the same time -- looks like Evertjan gets a hat-trick, wtg.

There is of course a property of the Request object called Form, and IIRC it
provides server-side access to a collection of name/value pairs, that
correspond directly with elements of the posted form. So it would seem the
actual case is that ASP *does* know about forms, the fields they contain and
the values of those fields... imagine that!

Anyway, back to the OP's question, your session variables reside on the
server, so only code running on the server can clear them. This must
somehow involve a round-trip to the server (that would not ordinarily be
needed just to reset a form.) Maybe you could set a flag in a hidden input
when the form is reset, and use it to invoke a branch that clears your
session items the next time the form is posted? There are probably
thousands of ways it might be done, but the gist is, you must communicate
the need to clear the session data to server-side code, such as an ASP
script.
-Mark
"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.242...
Kermit Piper wrote on 18 mrt 2006 in
microsoft.public.inetserver.asp.general:
Thank you Evertjan! I'll give it a try. How about clearing the form
field values, any ideas on that?


This is usenet, not email.
Please quote where you are responding on.

"form field values" are a clientside concept,
where ASP does not know about.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Mar 22 '06 #5
Mark J. McGinty wrote:
Thank you Evertjan! I'll give it a try. How about clearing
the form field values, any ideas on that?
"form field values" are a clientside concept,
where ASP does not know about.


Well that was condescending, useless and less than
technically correct, all at the same time -- looks like
Evertjan gets a hat-trick, wtg.
There is of course a property of the Request object called
Form, and IIRC it provides server-side access to a
collection of name/value pairs, that correspond directly
with elements of the posted form.


There may be such a collection, but ASP still does not understand the
concept of form fields, much less "clearing" them. The request was
*obviously* about the client-side.
So it would seem the actual case is that ASP *does* know
about forms, the fields they contain and the values of those
fields... imagine that!


Actually, ASP does not. I can populate the Request.Form collection without
one using any of the various XMLHttpRequest objects. No forms are required
to do so.
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Mar 22 '06 #6

"Dave Anderson" <GT**********@spammotel.com> wrote in message
news:u8**************@TK2MSFTNGP12.phx.gbl...
Mark J. McGinty wrote:
Thank you Evertjan! I'll give it a try. How about clearing
the form field values, any ideas on that?

"form field values" are a clientside concept,
where ASP does not know about.
Well that was condescending, useless and less than
technically correct, all at the same time -- looks like
Evertjan gets a hat-trick, wtg.
There is of course a property of the Request object called
Form, and IIRC it provides server-side access to a
collection of name/value pairs, that correspond directly
with elements of the posted form.


There may be such a collection, but ASP still does not understand the
concept of form fields, much less "clearing" them. The request was
*obviously* about the client-side.


Specifically his question involved clearing the session variables, values of
which he is using when he constructs HTML as a response. Clearing session
variables is *obviously* a server-side affair. The fact that, even more
specifically, he is using the values of those session variables to emit
value
attributes for input elements that are children of the form element he is
generating *would* be completely irrelevant, if not for the way he phrased
his question.

Now before I continue my rhetoric I want to point out that I totally respect
your contributions to the Usenet, Dave, I see substantial technical accuracy
and depth in your posts; you seem both knowledgeable and objective. I have
no issues with you... and I'm sure we both have better things to do than
split hairs for this NG -- seriously! :-)

As for the OP, he might've phrased his question a little better, and if he
had quoted his earlier posts, the additional context might even have negated
your incentive to retort. Otoh, I read most of this thread in one sitting,
had all the context fresh in mind, and to me the imperfections of his
request were slight.

To me the question does not justify a response that's constructed like this:
"[diminutive statement of the obvious] [cursory glance at the 'letter' (as
opposed to the spirit) of the question] [brush-off in the form of a trite
analogistic reference to what ASP does or does not 'know'] [explicitly void
of anything even remotely helpful to OP]"

Effective translation: "I'm replying to your foolish attempt at a post to
this NG for
the following reasons only: a.) To spank you for your breach of
netiquette -- the importance of which transcends that of even the Net
itself, much less the topic at hand;
b.) To carelessly label your question as OT, having given it very little
thought, if any at all; c.) Just to say, 'piss on you', as I reassert my
standing as a know-nothing, industrial strength, reagent grade asshole,
99.7% pure, recognized by multiple cultures worldwide."

Personally, I object to replies that are 100% admonition. Some people like
to suggest other NGs -- that's fine, but I also think it's pointless to
merely inform an OP that there is a line between server and client sides.
Often it's clear that the line is a blur to the OP -- why not try to help
them to sharpen their view of that line? How are they better off posting to
a client-side oriented NG, at the same level of confusion with which they
posted to this one?

If it's clear enough that their confusion has server-side implications, so
what if they used client-side terminology to express it?

Anyway, I suspect that the core issue here is whether you (or anyone else)
is more offended by Evertjan's uniquely rude style and the utter lack of
anything useful in many of his posts, or by my vocal objections thereto. I
like to think I'm open minded, and I surely do not stay where I'm unwanted;
I will defer to a consensus. Anyone who thinks it would be more appropriate
for me to simply STFU about it, please speak freely. I will respect the
wishes of the group.

So it would seem the actual case is that ASP *does* know
about forms, the fields they contain and the values of those
fields... imagine that!


Actually, ASP does not. I can populate the Request.Form collection without
one using any of the various XMLHttpRequest objects. No forms are required
to do so.


Heh, why stop there? Why not construct the entire HTTP request by hand and
write sockets code to send it up to the server without all that messy API
and object crap? Hell, dust off MASM and drive yourself crazy! :-)

But are you suggesting that knowledge of the underlying protocol somehow
proves that Request.Form is entirely unrelated to a form in an HTML document
that was used to submit the "Request"? (I really wanted to avoid splitting
any more hairs but couldn't resist.)
-Mark

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message.
Use of this email address implies consent to these terms. Please do not
contact me directly or ask me to contact you directly for assistance. If
your question is worth asking, it's worth posting.


Mar 24 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by bagsmode | last post: by
9 posts views Thread by netclectic | last post: by
1 post views Thread by Scott Walters | last post: by
reply views Thread by news.microsoft.com | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.