reading session variables in javascript??

Discussion in 'Software for Windows' started by Gow, Apr 30, 2003.

  1. Gow

    Gow Member

    Joined:
    Aug 10, 2000
    Messages:
    35
    Likes Received:
    0
    Hi there

    What i need is a site or some code that will allow me to read the contents of a session variable created in ASP...

    The thing is i want to read it using javascript, can someone help, please :D

    i have a 2d array created in ASP and stored in a session variable...

    I want to check the contents of the array against multiple form text boxes, and i need it done in javascript..

    can this be done?
    am i trying to do the imposible?

    i have searched for hours and not found an answer...

    All help greatfully accepted :)

    Thanks


     
  2. Argo

    Argo Lifer

    Joined:
    Apr 8, 2000
    Messages:
    10,047
    Likes Received:
    0
    There is no direct way. Session persists on the server, javascript runs on the client. Depending on what your goal is, the only workaround would be to have asp page write out different JSP based on what the value of the session variable is.

    You can also write a thread or asp page that will listen on a specific port and serve request for the jsp script running on the client. This solution is pretty cumbersome though.
     
  3. GilletteCat

    GilletteCat Member

    Joined:
    Dec 28, 2001
    Messages:
    181
    Likes Received:
    0
    let's say you have a one-dimentional VB-safe array and you have assigned it to a session variable on one page to be able to retrieve it on another.
    the code for the <head> of the retrieving page would be:
    <script language=javascript>
    var MyVBArray = new VBArray(<%=Session("MySessionArray_Blah_Blah")%>);
    var MyJSArray = MyVBArray.toArray();
    </script>
    If you want to compare the value of a text-box object on the page to a value in the array, you have to know which index in the array that value occupies. For example, we would compare the value of the text-box my_input_field_1 to the value of the first member of the array:
    <script language=javascript>
    if(document.myform.my_input_field_1.value == MyJSArray[0]) {
    .....
    }
    Remember, the array index is 0-based.

    Hope it helps.
     
  4. Argo

    Argo Lifer

    Joined:
    Apr 8, 2000
    Messages:
    10,047
    Likes Received:
    0
    GilletteCat:

    I had no idea there was a way to do that. I was thinking from JSP/Servlets perspective.
     
  5. GilletteCat

    GilletteCat Member

    Joined:
    Dec 28, 2001
    Messages:
    181
    Likes Received:
    0
    yeh, it's rather plain :)
    but, i guess, you have to have faced it once before to know it.
     
  6. eklass

    eklass Golden Member

    Joined:
    Mar 19, 2001
    Messages:
    1,218
    Likes Received:
    0
    you will have to read the session variable sfrom ASP and have them print out the javasript code to check for it

    in otherwords, use serverside code to create dynamic client-side code

    i do this when checking out in an ecommerce storre and the user wants t0o specify "same as billing" for thier shipping address. when the user clicks the checkbox, all the text boxes are fille din via javascript. the way javascipt know is i use php to print out:

    document.form[0].s_name.value = 'john doe';


    wherein the john dow part between the single quotes is a session vairable

    if you don't get it, read my sig. if you still dont' get it, maybe it's just over your head (the process, not the pancakes)
     
  7. Gow

    Gow Member

    Joined:
    Aug 10, 2000
    Messages:
    35
    Likes Received:
    0
    This does not work for me.....



    I don't know why, it just dont...

    I got this error mesage once..

    Response object, ASP 0106 (0x80020005)
    An unhandled data type was encountered.


    can anyone tell me how to read a normal session variable......

    is it somthing like

    var test = <%sesstion("test")%>;

    if i can get that to work i may be able to sort the rest out...
     
  8. eklass

    eklass Golden Member

    Joined:
    Mar 19, 2001
    Messages:
    1,218
    Likes Received:
    0
    this is what you need:


    <script>
    var something = '<%=Session("something_else")%>';
    </script>