Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    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


  2. #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,947 Times in 4,908 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
    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
       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 02:29 AM.
    Be yourself. No one else is as qualified.


Posting Permissions

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