Set cookie in javascript and retrieve it in vbscript ??

C

Colin Graham

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
 
K

kaeli

csgraham74 said:
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
 
E

Evertjan.

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.
 
K

kaeli

kaeli wrote on 25 apr 2005 in comp.lang.javascript:


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.

--
 
E

Evertjan.

kaeli wrote on 25 apr 2005 in comp.lang.javascript:
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?
 
K

kaeli

kaeli wrote on 25 apr 2005 in comp.lang.javascript:


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

--
 
E

Evertjan.

kaeli wrote on 25 apr 2005 in comp.lang.javascript:
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.
 
K

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.

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

--
 
E

Evertjan.

kaeli wrote on 25 apr 2005 in comp.lang.javascript:
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.
 
K

kaeli

kaeli wrote on 25 apr 2005 in comp.lang.javascript:


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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top