Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional 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
  #1 (permalink)  
Old November 30th, 2004, 02:50 PM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using the Session Object and JavaScript

I have a simple function and I am not able to assign the value of Session("PALType") to variable "SesType". I created Session("PALType") from my login page. I can write the Session value to my page using "Response.Write Session("PALType")" in the body of my page successfully. But I cannot assign it's value or use the Session Object itself for use in my If Statement.

Are we allowed to use Session("") and JavaScript together?

I have tried using "", '', and no quotes on either side of Session("PALType") but using '' is the only way that did not produce a error. Any help would be appreciated. Thank you in advance.

Function code is below:

function AdVal()
{

var SesType = 'Session("PALType")';
var AdminVal

//document.writeln(SesType)

if (SesType == "W2")
       {
         //document.writeln(SesType);
         AdminVal = document.frmDeal.AdminFee.value = "W2";
               }
      else
       {
         //document.writeln(SesType);
         AdminVal = document.frmDeal.AdminFee.value = "1099";
           }

return AdminVal;
}
  #2 (permalink)  
Old November 30th, 2004, 08:55 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: High Wycombe, UK, United Kingdom.
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

try :


function AdVal()
{
     var SesType = <%=Session("PALType")%>;

     // set the default value
     var AdminVal='1099';

      if (SesType == 'W2')
      {
          AdminVal = document.frmDeal.AdminFee.value = "W2";
      }

      return AdminVal;
}
  #3 (permalink)  
Old November 30th, 2004, 09:18 PM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help.

When I use your code sniplet I get the following error:
"Object Expected"

I am calling this function from the onblur event of a textbox using the following code:
<INPUT TYPE="Text" NAME="ProcessingFeeOutside" VALUE="0" onblur="AdVal()">


Rguidry

  #4 (permalink)  
Old November 30th, 2004, 09:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: High Wycombe, UK, United Kingdom.
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

I'm guessing that you are printing this out from ASP, so try the following instead, replace the line :

var SesType = <%=Session("PALType")%>;

with :

var SesType = '<%=Session("PALType")%>';
  #5 (permalink)  
Old November 30th, 2004, 09:33 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: High Wycombe, UK, United Kingdom.
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

You might also fine a Netscape based browser such as Netscape / Firefox helpful as they have a better Javascript Console and Debugger than IE does.
  #6 (permalink)  
Old December 1st, 2004, 05:52 AM
Authorized User
 
Join Date: Jun 2003
Location: Witham, Essex, United Kingdom.
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You could also try storing the session variable in a hidden form field and picking it up from there in your JS.

-------------------
System 3 2000 Limited
www.system3-2000.co.uk
  #7 (permalink)  
Old December 1st, 2004, 03:53 PM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Greg. I get the same "Object Expected" error.

  #8 (permalink)  
Old December 1st, 2004, 03:57 PM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Greg,

So you are saying that if I load Netscape and view my page in their browser I will have better debugging tools?

It would be nice to be able to debug and step through the code.

  #9 (permalink)  
Old December 1st, 2004, 06:56 PM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you all for your help! I started over using a blank page and with everyone's advice I got it to work using the following code:

function AdVal()
{

var SesType = '<%=Session("PALType")%>';
var AdminVal;

if (SesType == "W2")
       {
        AdminVal = document.frmDeal.AdminFee.value = "W2";
               }
      else
       {
         //document.writeln(SesType);
         AdminVal = document.frmDeal.AdminFee.value = "1099";
           }

return AdminVal;
}

  #10 (permalink)  
Old December 1st, 2004, 07:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: High Wycombe, UK, United Kingdom.
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

These browsers have a much more informative Javascript Console and also use a Javascript debugger - Venkman I think. I find them very useful in that regard, but you need to remember that your JS Code much work in them and not just IE for them to be of any real use.




Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript and the session object VictorVictor ASP.NET 2.0 Professional 3 April 1st, 2007 02:58 PM
javascript intellisense & session object VictorVictor ASP.NET 2.0 Professional 0 March 29th, 2007 10:59 AM
Session object keyvanjan Classic ASP Basics 1 January 25th, 2006 09:32 PM
Session Object mcinar Classic ASP Basics 9 January 9th, 2005 05:41 PM
session - javascript MartinK PHP How-To 2 November 17th, 2004 06:31 AM





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