• Session Variables

    Author
    Topic
    #371023

    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?

    Viewing 0 reply threads
    Author
    Replies
    • #588610

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

      var curpwd =

      HTH

      • #588827

        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.

        var vWelcome = “Welcome ”
        document.write(vWelcome)

        But when I changed the code to the following, not only did I get an error message, but ‘Welcome’ was not displayed.

        var vWelcome = “Welcome ”
        var vWelcomeName = <%=Session("vName")
        document.write(vWelcome+vWelcomeName)

        • #588829

          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 < – –

        • #588869

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

    Viewing 0 reply threads
    Reply To: Session Variables

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: