Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 29th, 2004, 02:49 AM
Registered User
Join Date: Oct 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Change session variable definitions

Further to Imar's notes on transferring variables between client and server sessions - I need to be able to change the definition of the session variable.
I want to feed a random number into the session command. That is, replace [02] in

strSc = String('<%=Session("strCopy")[02] %>');

with intQuotationIndex, so that I can pick up a different quotation each time.

I have had no success eventually resorting to the "Oh, nasty" solution as shown. That is fine as long the total number of quotes doesn't change - which it will!

<script type="text/javascript" >
//alert ('<% =Session("strCopy").length %>');
var intQuotationCount = ('<% =Session("strCopy").length %>');
//alert (intQuotationCount);
intQuotationIndex = Math.floor(Math.random() * intQuotationCount);
//alert (intQuotationIndex);
strSc = String('<%=Session("strCopy")[02] %>');
switch (intQuotationIndex)
case 1:
var strSc = new String('<%=Session("strCopy")[01] %>');
case 2:
var strSc = new String('<%=Session("strCopy")[02] %>');
case 3:
var strSc = new String('<%=Session("strCopy")[03] %>');
case 4:
var strSc = new String('<%=Session("strCopy")[04] %>');
var strSc = new String("Bad Number");
alert (strSc);

Any help would be appreciated.



Old October 29th, 2004, 03:25 AM
joefawcett's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

In your server side code thewn you must loop through the aray of quotes, Session("strCopy"), and write some client side script for each line:
Response.Write("var arrQuotes = new Array();\n");
(for var i = 1; i < Session("strCopy").length; i++)
  Response.Write("arrQuotes[" + i + "] = \"" + Session("strCopy")[i] + "\";\n"); 
Then you can access the quotes as an array client side.


Old October 29th, 2004, 03:45 AM
Registered User
Join Date: Oct 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks Joe - I will give that a try tomorrow.

Similar Threads
Thread Thread Starter Forum Replies Last Post
session and variable... badboy1 ASP.NET 3.5 Basics 1 August 3rd, 2008 09:14 AM
Can we get value of a session variable KamalRaturi ASP.NET 2.0 Professional 3 September 14th, 2006 03:33 PM
Session variable mrideout BOOK: Beginning ASP.NET 1.0 1 August 12th, 2004 07:01 PM
Session Variable mcdowell BOOK: Beginning ASP 3.0 5 June 20th, 2004 05:47 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.