Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 29th, 2004, 02:49 AM
Registered User
 
Join Date: Oct 2004
Location: Wauchope, NSW, Australia.
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] %>');
break
case 2:
var strSc = new String('<%=Session("strCopy")[02] %>');
break
case 3:
var strSc = new String('<%=Session("strCopy")[03] %>');
break
case 4:
var strSc = new String('<%=Session("strCopy")[04] %>');
break
default:
var strSc = new String("Bad Number");
break;
}
alert (strSc);
</script>

Any help would be appreciated.

Regards

Nick

Reply With Quote
  #2 (permalink)  
Old October 29th, 2004, 03:25 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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:
Code:
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.

--

Joe
Reply With Quote
  #3 (permalink)  
Old October 29th, 2004, 03:45 AM
Registered User
 
Join Date: Oct 2004
Location: Wauchope, NSW, Australia.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Joe - I will give that a try tomorrow.
Nick

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:51 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.