Setting option value to session var

Discussion in 'ASP General' started by Kermit Piper, Mar 17, 2006.

  1. Kermit Piper

    Kermit Piper Guest

    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
    Kermit Piper, Mar 17, 2006
    #1
    1. Advertising

  2. Kermit Piper

    Evertjan. Guest

    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)
    Evertjan., Mar 17, 2006
    #2
    1. Advertising

  3. Kermit Piper

    Kermit Piper Guest

    Thank you Evertjan! I'll give it a try. How about clearing the form
    field values, any ideas on that?
    Kermit Piper, Mar 18, 2006
    #3
  4. Kermit Piper

    Evertjan. Guest

    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)
    Evertjan., Mar 18, 2006
    #4
  5. 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." <> wrote in message
    news:Xns978A6B51B76CBeejj99@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)
    Mark J. McGinty, Mar 22, 2006
    #5
  6. 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.
    Dave Anderson, Mar 22, 2006
    #6
  7. "Dave Anderson" <> wrote in message
    news:...
    > 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.
    >
    Mark J. McGinty, Mar 24, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alvin Bruney

    Threads.. Session var lost, App var ok

    Alvin Bruney, Dec 2, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    343
    rooster575
    Dec 2, 2003
  2. thomson
    Replies:
    10
    Views:
    2,472
    Eliyahu Goldin
    Jun 20, 2005
  3. thomson
    Replies:
    0
    Views:
    358
    thomson
    Jun 20, 2005
  4. Fred
    Replies:
    3
    Views:
    312
    Alf P. Steinbach
    Aug 10, 2003
  5. Alex Vinokur
    Replies:
    4
    Views:
    462
    Ron Natalie
    Sep 24, 2003
Loading...

Share This Page