Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-07-2012, 10:03 PM   PM User | #1
ade
New to the CF scene

 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ade is an unknown quantity at this point
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.
ade is offline   Reply With Quote
Old 11-08-2012, 01:26 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,542
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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??
__________________
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.

Last edited by Old Pedant; 11-08-2012 at 01:29 AM..
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:39 AM.


Advertisement
Log in to turn off these ads.