Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    ade
    ade is offline
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Transferring input value from a page to the previous page

    Do you have an idea of how I can get the value of an html textbox input with id= keeper; I want to store its value into the cookie ‘firstname’ , so it can be used on the previous page, within the same session.

    This is VBScript(Wouldn't mind the JavaScript implementation)

    <%
    Response.Cookies("firstname")= document.getElementById("keeper").value
    fname=Request.Cookies("firstname")
    Response.write(fname)
    %>

    Thanks.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Ummm...that is VBScript, yes, but it is ASP code. *SERVER*-side code. Not code in the browser.

    And you can *NOT* use document.getElementById( ) in ASP code.

    If you need the cookie value in your ASP code, then you should stick to doing it this basic way. But instead do something like
    Code:
    Response.Cookies("firstname") = Trim(Request("keeper"))
    where "keeper" is the *NAME* of a form field in the page as submitted to ASP.

    However... With ASP code, you can *NOT* read the value of a cookie that was created or changed ON THE SAME PAGE.

    In other words, in the code you show there, when you do
    Code:
       fname = Request.Cookies("firstname")
    you would be getting the value of the cookie AS IT WAS WHEN THE PAGE WAS CALLED. The line above, where you set the cookie via Response.Cookies would *NOT* affect the value you get from Request.Cookies.

    This is different than in-browser code. Which makes sense: The value of a cookie *IS* a browser-side thing. If you change it in the browser, of course you can read it back immediately. But the ASP code won't change the value in the browser until the HTML generated by the ASP page is *sent* to the browser.

    &&&&&&&&&&&

    What I am REALLY curious about: How can the cookie I store right this second affect what the "previous page" contained when I viewed it 10 minutes ago. Are you expecting cookies to implement some kind of time machine??
    Last edited by Old Pedant; 11-08-2012 at 01:29 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •