473,624 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Session variable

I would like to set a Session variable to a value. In Vbscript it should be

Session("ZoomVa lue")=500

How can I set this session variable by using Javascript?

Thanks
Jul 23 '05 #1
3 12392
On Tue, 12 Oct 2004 20:56:52 +0800, "Enoch Chan" <si****@hotmail .com>
wrote:
I would like to set a Session variable to a value. In Vbscript it should be

Session("ZoomV alue")=500

How can I set this session variable by using Javascript?


Session.ZoomVal ue=500

Jim.
Jul 23 '05 #2
"Enoch Chan" <si****@hotmail .com> wrote in message news:<ck******* **@imsp212.netv igator.com>...
I would like to set a Session variable to a value. In Vbscript it should be

What do you mean by session variable?

Javascript has global variables. You can access global variables from
any child frame or child window.

Javascript has session cookies. You can save small amount of data in a
cookie. I have had problems with session cookies in IE and do not use
session cookies any more. Session cookies are cookie that do not
include a time value. Instead, I set an expiration time on the cookies
I create.

I suggest using an existing set of cookie routines. The
document.cookie can contain existing cookies.

~kaeli~ has developed some cookie code. You may view it in this
article:

http://groups.google.com/groups?hl=e...859-1&selm=MPG
..1af96c2a4f8ab c94989dcc%40nnt p.lucent.com

Also, ~kaeli~ reports that:
There's some even better code that sets more cookie properties like
domain, secure, path, etc here.
http://www.acm.uiuc.edu/webmonkeys/j...ipt/cookies.js

I wrote a short program for verifying cookies will work on a site.
The cookie code was taken from:
Functions from Using HTML 4, Java 1.1, and JavaScript 1.2:
Complete. Definitive. Invaluble.
by Eric Jim O'Donnell, et al.
and from the Netscape develper's site.

Robert

Here is my cookie testing
code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>Rememb er by cookie</title>
<script type="text/javascript">
// Sets cookie values. Expiration date is optional
//
function setCookie(name, value, expire) {
document.cookie = name + "=" + escape(value)
+ ((expire == null) ? "" : ("; expires=" + expire.toGMTStr ing()))
}
function getCookie(Name) {
var search = Name + "="
if (document.cooki e.length > 0) { // if there are any cookies
offset = document.cookie .indexOf(search )
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie .indexOf(";", offset)
// set index of end of cookie value
if (end == -1)
end = document.cookie .length
return unescape(docume nt.cookie.subst ring(offset, end))
}
}
}

function deleteCookie(na me,path,domain) {
if (getCookie(name )) document.cookie = name + "=" +
( (path) ? ";path=" + path : "") +
( (domain) ? ";domain=" + domain : "") +
";expires=T hu, 01-Jan-70 00:00:01 GMT";
}

function registerCookie( cookieName,cook ieValue) {
var today = new Date()
var expires = new Date()
expires.setTime (today.getTime( ) + 1000*60*60*24*3 65)
setCookie(cooki eName, cookieValue, expires)
}
</script>

<body>
<p>Let's see if we can set then read a cookie
<script type="text/javascript">
document.write( "when on (document.url) " + document.URL);
document.write( "</p>");

var all = "I hope this cookie doesn't crumble.";

document.write( "<p>");
document.write( "document.cooki e before deleteCookie = "
+ document.cookie + "<br><br>") ;
deleteCookie("m ycookietry");
document.write( "document.cooki e after deleteCookie= "
+ document.cookie + "<br><br>") ;

registerCookie( "mycookietry",a ll);

document.write( "document.cooki e after registerCookie = "
+ document.cookie + "<br><br>") ;

theMessage = getCookie("myco okietry");
document.write( "theMessage = " + theMessage + "<br>");
document.write( "</p>");
</SCRIPT>
</body>
</html>
Jul 23 '05 #3
JRS: In article <c6************ **************@ posting.google. com>,
dated Tue, 12 Oct 2004 13:17:40, seen in news:comp.lang. javascript,
Robert <rc*******@my-deja.com> posted :
function registerCookie( cookieName,cook ieValue) {
var today = new Date()
var expires = new Date()
expires.setTime (today.getTime( ) + 1000*60*60*24*3 65)
setCookie(cooki eName, cookieValue, expires)
}


function registerCookie( cookieName, cookieValue) {
var D = new Date()
D.setFullYear(D .getFullYear() + 1)
setCookie(cooki eName, cookieValue, D)
}

makes more sense.

In the original code, expires = new Date(0) would be better; it's
generally worth spending a character to save determining a date/time
which will not be used.

It seems that in most books the code is not good.

In that context, the final D is used in D.toGMTString() - that format is
undefined in ECMA-262, and in my system does not comply with the
apparent specification for a cookie date string. But the interpretation
of cookie date strings is probably liberal enough, at least for the time
being.

It would have been smarter to follow the US FIPS for cookie dates; that
would have given AIUI all the advantages of ISO 8601 without being
embarrassingly foreign.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
3341
by: doltharz | last post by:
Please Help me i'm doing something i though was to be REALLY EASY but it drives me crazy The complete code is at the end of the email (i mean newsgroup article), i always use Option Explicit and Response.Expires=-1,
1
3104
by: Ann Leland | last post by:
I have been using session variables to pass a user name from one ASP page to another inside framesets for 9 months and it stopped working this week. I have made no code changes but there was a "security update" installed on the server a few days ago but I can't find out exactly what it was. In the research I have done I found many articles on the subject of session variables in ASP pages inside framesets. From what I read a new...
2
13541
by: Eric | last post by:
Hi, I've a problem with trying to retrieve a session variable in an include file. Basically, the main asp creates a session variable: <% Session("var1") = "Hello" %> And then when I click on a button it refers to the include file, which I believe is all client-side code as there are no server <% %> tags.
4
1644
by: VB Programmer | last post by:
If I have a variable I want to share in my application what is the difference between just declaring a variable (Dim strMyVar as String) and using a session variable (Session("strMyVar"))? When should I use a session variable and when should I just declare it like normal? Thanks in advance!
9
2447
by: William LaMartin | last post by:
I have a problem, mentioned here before, of Session and Application variables disappearing at one site but not at others or on my development computer. The problem is illustrated by an example at http://www.lamartin.com/dotnet/sessiontestset.aspx, were I set Session, Application and Cache variables on the first page and then on the second page view them as the second page is refreshed every five seconds. Before 10 refreshes, the...
9
2376
by: Greg Linwood | last post by:
I'm having difficulty understanding Session state in ASP.Net. It's almost embarrassing asking this as I've been using ASP since it was first released & it really shouldn't be this hard to use - perhaps I'm just not very smart or perhaps MS is making this too hard for us sql bunnies to understand - I dunno, but I'd really appreciate someone explaining what I'm doing wrong here & perhaps suggest a better approach.. I'm familiar with use of...
4
1946
by: T Ralya | last post by:
I am told that ASP.NET controls the session ID and session variables, but that does not fit my symptoms. I am posting here as directed. I'm hoping that someone can at least recommend something to try to isolate the problem. I have a simple application that demonstrates my problem. Page 1, step1: SaveSessionVariableButton will create a string value, show it on screen, save it in a session variable and show the session ID on screen....
3
2901
by: Alan Wang | last post by:
Hi there, Once my application gets complicated and complicated. I found it's really hard to keep track of Session value I am using in my asp.net application. I am just wondering if anyone have any experience on how to keep track of session value. Any help it's appreciated. Thanks Alan
4
3436
by: Don Miller | last post by:
I am using a Session variable to hold a class object between ASP.NET pages (in VB). In my constructor I check to see if the Session variable exists, and if it doesn't, I create one and populate it with "Me". But if the Session variable already exists, I would like the new object be populated with everything from the object stored in the Session variable. Ideally, I'd like to retrieve the object from the Session variable and assign it to...
17
5084
by: Control Freq | last post by:
Hi, Not sure if this is the right NG for this, but, is there a convention for the variable names of a Session variable? I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any guidance appreciated. Regards
0
8170
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8334
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6108
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2604
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.