Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Aug 2001
    Location
    USA
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Session Variables

    Can Session Variables be read by client-side JavaScript performing form validation, or are these variables only available to VBScript?

    On a login asp page I create a session variable vPwd that is set to the login password.

    On the asp page where the user can change their password I tried to accomplish the following in the client-side validation:

    var curpwd = Session("vPwd")
    if (theForm.CurrentPassword.value != curpwd)
    {
    alert("You did not enter the password with which you loged in.");
    theForm.CurrentPassword.focus();
    return (false);
    }

    When I ran the code, I received an error message regarding 'object expected' pointing to the line with the If.

    To test, I changed
    var curpwd = Session("vPwd")
    to
    var curpwd = "edc2839"

    The error message stopped appearing.

    Is there a way I can get JavaScript to read Session variables?

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Session Variables

    You can use an ASP tag in the Javascript block - like:

    var curpwd = <%=Session("vPwd")%>


    HTH

  3. #3
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Session Variables

    You're going to have to post again. Be sure not to use Comment tags in your code or it will appear hidden (as in your previous post. Use a space so the browser doesn't hide the code: < -- or < - -

  4. #4
    2 Star Lounger
    Join Date
    Aug 2001
    Location
    USA
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Session Variables

    I tried your answer, but it doesn't seem to work. Perhaps I misunderstood your coding.

    The following code displayed the word 'Welcome' in the browser window.
    <script language="JavaScript">
    var vWelcome = "Welcome "
    document.write(vWelcome)
    </script>

    But when I changed the code to the following, not only did I get an error message, but 'Welcome' was not displayed.
    <script language="JavaScript">
    var vWelcome = "Welcome "
    var vWelcomeName = <%=Session("vName")
    document.write(vWelcome+vWelcomeName)
    </script>

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Session Variables

    Check for the closing %> in your ASP page. It's not in your post.

Posting Permissions

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