Results 1 to 6 of 6

Thread: Session variables & Javascript in .asp

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Canada
    Posts
    70
    Code:

    <!-- #include file="./Include/Constants.asp" -->
    <HTML>
    <HEAD><TITLE>Reporting Index</TITLE>
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function myFunc(number) {
    ...
    window.alert (<% Session("GroupPass") %> );
    ...
    }
    // End -->
    </SCRIPT>
    </HEAD>
    <%
    If request.form("SaveInfo") = "Save Info" then
    Session("GroupPass")= 10 Session("InfoSet")= 1
    end if
    %>
    <BODY>
    ...
    </BODY>
    </HTML>

    Problem:
    The Session("GroupPass") variable is set to 10 yet when I use it in the alert I get a value of NaN.

    How can I keep track of the GroupPass value in Javascript?

    Thanks in advance,
    rlb_wpg

  2. #2
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Do this...

    Code:
    <% 
      If request.form("SaveInfo") = "Save Info" then 
        Session("GroupPass")= 10
        Session("InfoSet")= 1 
      end if 
    %>
    
    <!-- #include file="./Include/Constants.asp" --> 
    
    <HTML> 
    
    <HEAD>
    <TITLE>Reporting Index</TITLE> 
    </HEAD> 
    
    <SCRIPT LANGUAGE="JavaScript"> 
    
      function myFunc(number) { 
        window.alert (<% Session("GroupPass") %> ); 
      } 
    
    </SCRIPT>
    This way you will actually set GroupPass before you use it.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    you need quotes in that window.alert..

    window.alert("<% blah %>")
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Canada
    Posts
    70
    Ok, I've moved where I set the session variables to the top of file.
    <%
    If request.form("DoInfo") = "Save Info" then
    'SET Session Info HERE
    Session("GroupPass")= 10
    Session("InfoSet")= 1
    end if
    %>
    <!-- #include file="./Include/Constants.asp" -->
    <html>
    <HEAD>
    <TITLE>Reporting Index</TITLE>
    </HEAD>

    <SCRIPT LANGUAGE="JavaScript">

    function myFunc(number) {
    window.alert (<% Session("GroupPass") %> );
    }

    </SCRIPT>
    ...

    I tried each of these:
    1.
    window.alert ("'" + <% Session("GroupPass") %> + "'" );
    Produces 'NaN
    2.
    window.alert ("<% Session"GroupPass") %>" );
    -> Produces a blank
    3.
    window.alert (<% Session"GroupPass") %>);
    -> Produces a blank


    Thanks for your input so far, do you have any other suggestions?

  5. #5
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Code:
    <%=Session("GroupPass")%>
    With the equal.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Canada
    Posts
    70
    Perfect. Thanks so much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width