Welcome to WebmasterWorld Guest from 35.153.73.72

Forum Moderators: open

Message Too Old, No Replies

Privacy and Cookies

Passing cookies between pages

     
11:53 pm on Jul 28, 2005 (gmt 0)

New User

10+ Year Member

joined:June 21, 2003
posts:32
votes: 0


Hi,

All I want to do is pass some basic details from a form on the index.htm page to 2.htm using cookies, I am using the code below:

>>>index.htm

<html>
<head>
<title></title>
<script language="JavaScript">
function process(){
var firstname = document.form1.firstnametxt.value;
var business = document.form1.businesstxt.value;
var county = document.form1.countytxt.value;

var stuff_for_cookie = firstname + "#*$!" + business + "xxx" + county;

document.cookie = escape(stuff_for_cookie);
window.location = "2.htm";
}
</script>
</head>
<body>
<form name="form1">

<input type="text" size=15 name="firstnametxt"><br><br><br>

<input type="text" size=15 name="businesstxt"><br><br><br>

<input type="text" size=20 name="countytxt"><br><br><br>

<input type="button" value="Submit" onClick="process()">
</form>
<p>&nbsp;</p>
</body>
</html>

>>> 2.htm

<html>
<head>
<title></title>
<script language="JavaScript">
var cookie_stuff = unescape(document.cookie);
var crumbs = cookie_stuff.split("xxx");

var firstname = crumbs[0];
var business = crumbs[1];
var county = crumbs[2];
</script>
</head>

<body>
<script language="JavaScript">document.write(firstname)</script> we .....
</body>
</html>

The problem is when testing with different privacy settings, the cookie gets blocked on low settings. When comparing to other sites they get through fine (like WebmasterWorld, Amazon, and smaller sites)

My JS, php, privacy and alike knowledge is cr*p, so any working examples on how I can pass the data from page to page even when the user has high privacy settings (IE) would be great. (This is not for spamming or dishonest use).

Thanks in advance
Chris

dcrombie

11:26 am on July 29, 2005 (gmt 0)

Inactive Member
Account Expired

 
 


To set a cookie properly, you need:

document.cookie = "name=value";

wheras your code just has:

document.cookie = "value";

Try searching for a setCookie/getCookie function.