If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Javascript question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-05-04, 16:34
MBJ MBJ is offline
Registered User
 
Join Date: Jul 2004
Posts: 24
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??
Reply With Quote
  #2 (permalink)  
Old 08-05-04, 16:48
Gaz2k Gaz2k is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 08-05-04, 19:08
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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 19:12.
Reply With Quote
  #4 (permalink)  
Old 08-06-04, 12:15
MBJ MBJ is offline
Registered User
 
Join Date: Jul 2004
Posts: 24
Worked like a dream.. thanks. I had to modify the function, but it worked.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On