View Single Post
Join Date: Feb 2005
Posts: 355
Reputation: DanceInstructor is an unknown quantity at this point 
Solved Threads: 14
DanceInstructor's Avatar
DanceInstructor DanceInstructor is offline Offline
Posting Whiz

Re: Passing data from forms from one page to another

 
0
  #10
Mar 11th, 2005
These are the fuctions you need. I suggest you make a file called cookie.js and include in your html file like this:

[HTML]<script type="text/javascript" src="cookie.js"></script>[/HTML]

and the javascript to place in the cookie.js file:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. //
  2. // Cookie Functions -- "Night of the Living Cookie" Version (25-Jul-96)
  3. //
  4. // Written by: Bill Dortch, hIdaho Design <bdortch@hidaho.com>
  5. // The following functions are released to the public domain.
  6. //
  7. // This version takes a more aggressive approach to deleting
  8. // cookies. Previous versions set the expiration date to one
  9. // millisecond prior to the current time; however, this method
  10. // did not work in Netscape 2.02 (though it does in earlier and
  11. // later versions), resulting in "zombie" cookies that would not
  12. // die. DeleteCookie now sets the expiration date to the earliest
  13. // usable date (one second into 1970), and sets the cookie's value
  14. // to null for good measure.
  15. //
  16. // Also, this version adds optional path and domain parameters to
  17. // the DeleteCookie function. If you specify a path and/or domain
  18. // when creating (setting) a cookie**, you must specify the same
  19. // path/domain when deleting it, or deletion will not occur.
  20. //
  21. // The FixCookieDate function must now be called explicitly to
  22. // correct for the 2.x Mac date bug. This function should be
  23. // called *once* after a Date object is created and before it
  24. // is passed (as an expiration date) to SetCookie. Because the
  25. // Mac date bug affects all dates, not just those passed to
  26. // SetCookie, you might want to make it a habit to call
  27. // FixCookieDate any time you create a new Date object:
  28. //
  29. // var theDate = new Date();
  30. // FixCookieDate (theDate);
  31. //
  32. // Calling FixCookieDate has no effect on platforms other than
  33. // the Mac, so there is no need to determine the user's platform
  34. // prior to calling it.
  35. //
  36. // This version also incorporates several minor coding improvements.
  37. //
  38. // **Note that it is possible to set multiple cookies with the same
  39. // name but different (nested) paths. For example:
  40. //
  41. // SetCookie ("color","red",null,"/outer");
  42. // SetCookie ("color","blue",null,"/outer/inner");
  43. //
  44. // However, GetCookie cannot distinguish between these and will return
  45. // the first cookie that matches a given name. It is therefore
  46. // recommended that you *not* use the same name for cookies with
  47. // different paths. (Bear in mind that there is *always* a path
  48. // associated with a cookie; if you don't explicitly specify one,
  49. // the path of the setting document is used.)
  50. //
  51. // Revision History:
  52. //
  53. // "Toss Your Cookies" Version (22-Mar-96)
  54. // - Added FixCookieDate() function to correct for Mac date bug
  55. //
  56. // "Second Helping" Version (21-Jan-96)
  57. // - Added path, domain and secure parameters to SetCookie
  58. // - Replaced home-rolled encode/decode functions with Netscape's
  59. // new (then) escape and unescape functions
  60. //
  61. // "Free Cookies" Version (December 95)
  62. //
  63. //
  64. // For information on the significance of cookie parameters,
  65. // and on cookies in general, please refer to the official cookie
  66. // spec, at:
  67. //
  68. // http://www.netscape.com/newsref/std/cookie_spec.html
  69. //
  70. //******************************************************************
  71. //
  72. // "Internal" function to return the decoded value of a cookie
  73. //
  74. function getCookieVal (offset) {
  75. var endstr = document.cookie.indexOf (";", offset);
  76. if (endstr == -1) {
  77. endstr = document.cookie.length;
  78. }
  79. return unescape(document.cookie.substring(offset, endstr));
  80. }
  81.  
  82. //
  83. // Function to correct for 2.x Mac date bug. Call this function to
  84. // fix a date object prior to passing it to SetCookie.
  85. // IMPORTANT: This function should only be called *once* for
  86. // any given date object! See example at the end of this document.
  87. //
  88. function FixCookieDate (date) {
  89. var base = new Date(0);
  90. var skew = base.getTime(); // dawn of (Unix) time - should be 0
  91. if (skew > 0) { // Except on the Mac - ahead of its time
  92. date.setTime (date.getTime() - skew);
  93. }
  94. }
  95.  
  96. //
  97. // Function to return the value of the cookie specified by "name".
  98. // name - String object containing the cookie name.
  99. // returns - String object containing the cookie value, or null if
  100. // the cookie does not exist.
  101. //
  102. function GetCookie (name) {
  103. var arg = name + "=";
  104. var alen = arg.length;
  105. var clen = document.cookie.length;
  106. var i = 0;
  107. while (i < clen) {
  108. var j = i + alen;
  109. if (document.cookie.substring(i, j) == arg) {
  110. return getCookieVal (j);
  111. }
  112. i = document.cookie.indexOf(" ", i) + 1;
  113. if (i == 0) {
  114. break;
  115. }
  116. }
  117. return null;
  118. }
  119.  
  120. //
  121. // Function to create or update a cookie.
  122. // name - String object containing the cookie name.
  123. // value - String object containing the cookie value. May contain
  124. // any valid string characters.
  125. // [expires] - Date object containing the expiration data of the cookie. If
  126. // omitted or null, expires the cookie at the end of the current session.
  127. // [path] - String object indicating the path for which the cookie is valid.
  128. // If omitted or null, uses the path of the calling document.
  129. // [domain] - String object indicating the domain for which the cookie is
  130. // valid. If omitted or null, uses the domain of the calling document.
  131. // [secure] - Boolean (true/false) value indicating whether cookie transmission
  132. // requires a secure channel (HTTPS).
  133. //
  134. // The first two parameters are required. The others, if supplied, must
  135. // be passed in the order listed above. To omit an unused optional field,
  136. // use null as a place holder. For example, to call SetCookie using name,
  137. // value and path, you would code:
  138. //
  139. // SetCookie ("myCookieName", "myCookieValue", null, "/");
  140. //
  141. // Note that trailing omitted parameters do not require a placeholder.
  142. //
  143. // To set a secure cookie for path "/myPath", that expires after the
  144. // current session, you might code:
  145. //
  146. // SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
  147. //
  148. function SetCookie (name,value,expires,path,domain,secure) {
  149. document.cookie = name + "=" + escape (value) +
  150. ((expires) ? "; expires=" + expires.toGMTString() : "") +
  151. ((path) ? "; path=" + path : "") +
  152. ((domain) ? "; domain=" + domain : "") +
  153. ((secure) ? "; secure" : "");
  154. }
  155.  
  156. // Function to delete a cookie. (Sets expiration date to start of epoch)
  157. // name - String object containing the cookie name
  158. // path - String object containing the path of the cookie to delete. This MUST
  159. // be the same as the path used to create the cookie, or null/omitted if
  160. // no path was specified when creating the cookie.
  161. // domain - String object containing the domain of the cookie to delete. This MUST
  162. // be the same as the domain used to create the cookie, or null/omitted if
  163. // no domain was specified when creating the cookie.
  164. //
  165. function DeleteCookie (name,path,domain) {
  166. if (GetCookie(name)) {
  167. document.cookie = name + "=" +
  168. ((path) ? "; path=" + path : "") +
  169. ((domain) ? "; domain=" + domain : "") +
  170. "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  171. }
  172. }

This code has served me well

Dance
Clear Mind Hosting and Web Design

If I've helped you please consider adding to my reputation.
Reply With Quote