Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Posts
    24

    Unanswered: Javascript question

    I need to set a cookie or a session variable in an event function in javascript. How do I access the request object or session object in my function

    eg

    <button type="button" onclick="do_click()">Login</button>

    <script language="javascript">
    function do_click()
    {

    Response.Cookies("xyz")("cookie1") = "success";

    //or

    Session("cookie1") = "success";

    }

    however, I am unable to achieve the above because I cannot directly access the Response or Session object in the function do_click().

    Anyone has any ideas??

  2. #2
    Join Date
    Aug 2004
    Posts
    7
    Do This,

    <button type="button" onclick="do_click()">Login</button>

    <script language="javascript">
    function do_click()
    {

    <% Response.Cookies("xyz")("cookie1") = "success" %>

    //or

    <% Session("cookie1") = "success" %>

    }

    you don't need the semi-colons in asp

  3. #3
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Hmmm Kay.....

    this was kinda ripped from this site...

    http://javascript.internet.com/passwords/cookie-in.html


    Code:
    <button type="button" onclick="do_click()">Login</button>
    
    <script language="javascript">
    function do_click() {
      SetCookie('FreeStuffL', FreeStuffL_Name, expdate); 
    }
    
    function SetCookie (name, value)  {
      var argv = SetCookie.arguments;
      var argc = SetCookie.arguments.length;
      var expires = (argc > 2) ? argv[2] : null;
      var path = (argc > 3) ? argv[3] : null;
      var domain = (argc > 4) ? argv[4] : null;
      var secure = (argc > 5) ? argv[5] : false;
      document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
    }
    I suspect it needs changing as the function have 2 arguements but three are passed but it should get you started.
    Last edited by rokslide; 08-05-04 at 20:12.

  4. #4
    Join Date
    Jul 2004
    Posts
    24
    Worked like a dream.. thanks. I had to modify the function, but it worked.

Posting Permissions

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