By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,175 Members | 1,689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,175 IT Pros & Developers. It's quick & easy.

Set cookie in javascript and retrieve it in vbscript ??

P: n/a
hi folks,

just wonder if this is possible or is there a better way of doing
this. i need to store values in cookies between two forms. the details
are added in a popup when this is closed the main form stores these
values in hidden fields. at this point xml is built up and submitted
to a biztalk server. if there is an error the page is refreshed and
the initial values i added via the popup are lost.

my idea was to store these as cookies and populate the main form that
way if there is an error. My popup uses the following to send details
back to main form. e.g.,
window.opener.document.all.Doors.value=form1.Doors .value;

i have only ever used the following to set cookies in vbscript
<input type="hidden" value="<%=Request.Cookies("Doors")%>"
name="Doors" >

how can i set and get cookies using purely javascript ??? any examples
greatly appreciated.

Thanks in advance.

CG
Jul 23 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
In article <ee**************************@posting.google.com >, csgraham74
@hotmail.com enlightened us with...
hi folks,

just wonder if this is possible or is there a better way of doing
this.
Best way (IMO) is with session variables, that way if someone has cookies
turned off or JS turned off, it still works.

i have only ever used the following to set cookies in vbscript
<input type="hidden" value="<%=Request.Cookies("Doors")%>"
name="Doors" >

how can i set and get cookies using purely javascript ??? any examples
greatly appreciated.


Not like this. ;)
You'd have to set the cookie by calling a function somewhere, probably form
onsubmit. And you can't call javascript code in a value like you do here with
ASP.
There are cookie functions posted here all the time, so a quick Google of the
group should bring some up. If you can't find any, I have a very simplistic
cookie function set (check, set, and get, simple values, no domains) in my
useful section in Kaeli's Space (see my sig).

--
--
~kaeli~
The Bermuda Triangle got tired of warm weather. It moved to
Finland. Now Santa Claus is missing.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2

P: n/a
kaeli wrote on 25 apr 2005 in comp.lang.javascript:
Best way (IMO) is with session variables, that way if someone has
cookies turned off or JS turned off, it still works.


Not exactly.
If session cookies are also turned off,
every page is a new session,
without any session variables to start with.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #3

P: n/a
In article <Xn********************@194.109.133.29>,
ex**************@interxnl.net enlightened us with...
kaeli wrote on 25 apr 2005 in comp.lang.javascript:
Best way (IMO) is with session variables, that way if someone has
cookies turned off or JS turned off, it still works.


Not exactly.
If session cookies are also turned off,
every page is a new session,
without any session variables to start with.


Most servers I have worked with fall back to URL re-writing if session
cookies are disabled.
If yours does not, then you should have all sessions use URL re-writing for
precisely this reason.

i.e. from the weblogic docs:
Using URL Rewriting Instead of Cookies
In some situations, a browser or wireless device may not accept cookies,
which makes session tracking with cookies impossible. URL rewriting is a
solution to this situation that can be substituted automatically when
WebLogic Server detects that the browser does not accept cookies.

--
--
~kaeli~
The secret of the universe is @*&^^^ NO CARRIER
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #4

P: n/a
kaeli wrote on 25 apr 2005 in comp.lang.javascript:
In article <Xn********************@194.109.133.29>,
ex**************@interxnl.net enlightened us with...
kaeli wrote on 25 apr 2005 in comp.lang.javascript:
> Best way (IMO) is with session variables, that way if someone has
> cookies turned off or JS turned off, it still works.
>
Not exactly.
If session cookies are also turned off,
every page is a new session,
without any session variables to start with.


Most servers I have worked with fall back to URL re-writing if session
cookies are disabled.


I have no idea what you are talking about.

Are you talking ASP, Kaeli?
If yours does not, then you should have all sessions use URL
re-writing for precisely this reason.

i.e. from the weblogic docs:
Using URL Rewriting Instead of Cookies
In some situations, a browser or wireless device may not accept
cookies, which makes session tracking with cookies impossible. URL
rewriting is a solution to this situation that can be substituted
automatically when WebLogic Server detects that the browser does not
accept cookies.


--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #5

P: n/a
In article <Xn*******************@194.109.133.29>,
ex**************@interxnl.net enlightened us with...
kaeli wrote on 25 apr 2005 in comp.lang.javascript:
In article <Xn********************@194.109.133.29>,
ex**************@interxnl.net enlightened us with...
kaeli wrote on 25 apr 2005 in comp.lang.javascript:

> Best way (IMO) is with session variables, that way if someone has
> cookies turned off or JS turned off, it still works.
>

Not exactly.
If session cookies are also turned off,
every page is a new session,
without any session variables to start with.

Most servers I have worked with fall back to URL re-writing if session
cookies are disabled.


I have no idea what you are talking about.


Then why did you argue? ;)

Are you talking ASP, Kaeli?


No, actually Weblogic (WSAD) is JSP.
But ASP (IIS) can do it too. As can Cold Fusion. I don't think Apache /
Tomcat can auto-detect, but I dunno for sure. I don't think NES (Iplanet)
can, either, but 6.0 had some nice changes, so maybe it can now.

Session variables != session cookie.

Session variables are used (implemented) by a web server, but generally
implemented by whatever server-side scripting language you're using.
This has nothing at all to do with javascript unless we're talking JScript
with .net or some such. The OP said he was open to other ideas, so I gave him
one.
For example, in my web app, I store the user's name in a session variable,
along with several user preferences. These are loaded from the DB when the
user logs in. They are not stored on the client. The client gets only a
session ID, which points to that data on the server so I don't have to query
the DB over and over. Then, I can do something like
<p>Welcome <%= sessionBean.getUserName() %></p>

HTH

--
--
~kaeli~
I do whatever my Rice Krispies tell me to.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #6

P: n/a
kaeli wrote on 25 apr 2005 in comp.lang.javascript:
Are you talking ASP, Kaeli?


No, actually Weblogic (WSAD) is JSP.
But ASP (IIS) can do it too. As can Cold Fusion. I don't think Apache
/ Tomcat can auto-detect, but I dunno for sure. I don't think NES
(Iplanet) can, either, but 6.0 had some nice changes, so maybe it can
now.

Session variables != session cookie.

Session variables are used (implemented) by a web server, but
generally implemented by whatever server-side scripting language
you're using. This has nothing at all to do with javascript unless
we're talking JScript with .net or some such. The OP said he was open
to other ideas, so I gave him one.
For example, in my web app, I store the user's name in a session
variable, along with several user preferences. These are loaded from
the DB when the user logs in. They are not stored on the client. The
client gets only a session ID, which points to that data on the server
so I don't have to query the DB over and over. Then, I can do
something like <p>Welcome <%= sessionBean.getUserName() %></p>


This is neither here nor there, Kaeli.

If the server does not recognize the client session, the server can store
al it likes, but does not know which client connection and session the
stored data belong to.

So the server either needs a session cookie [a cookie that expires at the
closing of the browser, also named ram-cookie] or a session code has to be
sent as a form or query value with all pages.

Is it the latter you mean.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #7

P: n/a
In article <Xn********************@194.109.133.29>,
ex**************@interxnl.net enlightened us with...

If the server does not recognize the client session, the server can store
al it likes, but does not know which client connection and session the
stored data belong to.


Yes, it does.
It uses the URL if it can't use cookies. As I said.

--
--
~kaeli~
A chicken crossing the road is poultry in motion.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #8

P: n/a
kaeli wrote on 25 apr 2005 in comp.lang.javascript:
In article <Xn********************@194.109.133.29>,
ex**************@interxnl.net enlightened us with...

If the server does not recognize the client session, the server can
store al it likes, but does not know which client connection and
session the stored data belong to.


Yes, it does.
It uses the URL if it can't use cookies. As I said.


A strange way of describing URL.
I would call it the querystring.

Anyway, since my users want something from me,
I am not going to accomodate them.

If they switch off ram-cookies, they loose functionality.

If they buy a car,
they should know it does not run without petrol,
and I am not going to push it.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #9

P: n/a
In article <Xn********************@194.109.133.29>,
ex**************@interxnl.net enlightened us with...
kaeli wrote on 25 apr 2005 in comp.lang.javascript:
In article <Xn********************@194.109.133.29>,
ex**************@interxnl.net enlightened us with...

If the server does not recognize the client session, the server can
store al it likes, but does not know which client connection and
session the stored data belong to.


Yes, it does.
It uses the URL if it can't use cookies. As I said.


A strange way of describing URL.
I would call it the querystring.

Anyway, since my users want something from me,
I am not going to accomodate them.


You don't work on e-commerce and B2B applications, do you?

--
--
~kaeli~
If a chicken and a half can lay an egg and a half in a day
and a half, how long would it take for a monkey with a
wooden leg to kick the dill seeds out of a pickle?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.