Setting option value to session var

K

Kermit Piper

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
 
E

Evertjan.

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="AK">AK</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
 
K

Kermit Piper

Thank you Evertjan! I'll give it a try. How about clearing the form
field values, any ideas on that?
 
E

Evertjan.

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.
 
M

Mark J. McGinty

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
 
D

Dave Anderson

Mark said:
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.
 
M

Mark J. McGinty

Dave Anderson said:
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.

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top