I have a simple webpage to test the functionality of a cookie. THe user chooses an animal from the menu, and if the checkbox is selected, the cookie is written and the document loads another page. After the cookie is set, a ReadCookie function is called to redirect the user.
When I click on GO, I get a "Page cannot be displayed" error. What am I doing wrong?
When I click on GO, I get a "Page cannot be displayed" error. What am I doing wrong?
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Cookie Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function SetCookie() {
var box = document.form1.region.options;
var chosen_value = box[box.selectedIndex].value;
if (document.form1.remember.checked == true){
var expiration = new Date("December 1, 2004");
expiration = expiration.toGMTString();
document.cookie = "name=" + chosen_value + ";expires=" + expiration;
alert(document.cookie);
}
Redirect(chosen_value);
}
function Redirect(choice) {
var url = 'none.html';
if (choice != null) {
switch (choice) {
case 'americas' : url = 'cat.html';
break;
case 'canada' : url = 'dog.html';
break;
case 'other' : url = 'eel.html';
break;
}
document.location = url;
}
else {
alert("Please select a region and click \"Go\".");
}
}
function ReadCookie() {
if (document.cookie != "") {
var url = 'error.html';
cookie_data = document.cookie;
switch (cookie_data) {
case 'americas' : url = 'cat.html';
break;
case 'canada' : url = 'dog.html';
break;
case 'other' : url = 'eel.html';
break;
}
document.location = url;
}
else {return}
}
// End -->
</script>
</head>
<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" onLoad="ReadCookie()">
<form method="post" name="form1">
<select name="region">
<option value="americas">USA/Latin America</option>
<option value="canada">Canada</option>
<option value="other">Other Regions</option>
</select>
<input type="submit" name="Submit" value="Go" onClick="setCookie()">
<input type="checkbox" name="remember" value="yes">
Remember my selection</td>
</form>
</body>
</html>