i don't know if this is what you mean,
however.
the following code is bug free, as far as i remember.
it is taken from the tutorial about js.cookies on
www.webmonkey.com.
i had to correct some bugs to make it bullet proof.
in any case i am not using js.cookies any more.
they are incredibly more complicated then using asp.cookies.
if you want such code i would be more than happy to deliver it to you.l

enjoy

assaf

/////////////////////
file: use_cookies.htm
/////////////////////
    <script>
     // check if user is logged on, even without a cookie
     // better display this stuff so that the user can, at will use a
different account

     var user_name;
     var password;

     var cookie_information = new Array();
     readTheCookie(cookie_information,cookieName);
     user_name=cookie_information["user_name"];
     password=cookie_information["password"];
     if(user_name && password){
      //simply put the two controls anywhere - they are hidden!
      document.write("<input type=hidden name=user_name value=" + user_name
+ ">");
      document.write("<input type=hidden name=password value=" + password +
">");
     }else{

      // place the controls neatly in a table
      document.write("<tr>");
       document.write("<td>");
        document.write("user name:");
       document.write("</td>");
       document.write("<td>");
        document.write("<input type=text name=user_name value='ex:
joe_shmoe'>");
       document.write("</td>");
      document.write("</tr>");
      document.write("<tr>");
       document.write("<td>");
        document.write("password:");
       document.write("</td>");
       document.write("<td>");
        document.write("<input type=password name=password
value='1234567890'>");
       document.write("</td>");
      document.write("</tr>");
     }
    </script>

/////////////////////
end of file: use_cookies.htm
/////////////////////
/////////////////////
cookies.js
///////////////////
 var cookieName="user_info";

 function setCookie(the_name,the_password)
 {
  var the_cookie = cookieName+"=user_name=" + escape(the_name) +
"&password=" + escape(the_password);
  //var the_date = new Date("December 31, 2050");
  //var the_cookie_date = the_date.toGMTString();
  //the_cookie = the_cookie + ";expires=" + the_cookie_date;
  document.cookie = the_cookie;
 }
 function readTheCookie(the_info,cookieName)
 {
  // load the cookie into a variable and unescape it
  var the_cookie = document.cookie;
  var the_cookie = unescape(the_cookie);
  // separate the user-part of the cokie from the system-part
  var user_system_broken_cookie = the_cookie.split(";");
  // look for the cookie name: user_info=
  // now look for the user_value that starts with the
  // "user_info=" value
  for (loop = 0; loop < user_system_broken_cookie.length; loop++)
  {
   // trim left spaces find a better way
   //debugger;
   var trimmed_str=user_system_broken_cookie[loop].replace(" ","");
   if(trimmed_str.indexOf(cookieName)==0)
    break;
  }
  if(user_system_broken_cookie.length==loop)
   // there are no cookies in this computer
   return;
  // remove the "cookieName=" from the start of the string
  var
user_values_str_location=user_system_broken_cookie[loop].indexOf("=")+1;
  var
user_values_str=user_system_broken_cookie[loop].substr(user_values_str_locat
ion);
  var separated_values = user_values_str.split("&");
  // loop through the list of name=values and load
  // up the associate array
  var property_value = "";
  for (loop = 0; loop < separated_values.length; loop++)
  {
   property_value = separated_values[loop];
   var broken_info = property_value.split("=");
   var the_property = broken_info[0];
   var the_value = broken_info[1];
   the_info[the_property] = the_value;
  }
 }
///////////////////////////////////////
end of file: cookies.js
//////////////////////////////////
----- Original Message -----
From: "Arockia Joseph" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, October 25, 2000 7:25 AM
Subject: cookies


> hai
> i wanna know whether one can access(retrieve) "user-info" from cookies
using
> JavaScript..
>
> if yes , can any one send their code ,i need it very urgently..
> bye guys
> joseph c.arockia
> --
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to