thejackkelly
07-17-2010, 11:33 PM
Hello. My goal is for the user's input on their first visit to redirect their landing page in the future. I am a novice and any help is very much appreciated.
The form's drop down menu includes three cities (Calgary, Toronto, Vancouver). When the user presses "submit form", the script should create a cookie to store the user's city selection. Next time the user visits the site, they should be redirected to their city's site, ie. "/vancouver.html"
Right now, the code is returning an error from the onload("redirect();") function. The error indicates I am trying to redirect to "/[object HTMLSelectElement].html", but I am not sure if the trouble is in reading or writing the cookie. For simplicity, I've removed most of the other content from this page (my cookie.js is attached as a .doc):
<title>Site Title</title>
<script type="text/javascript" src="cookie.js"></script>
<script language="JavaScript" type="text/javascript">
function redirect() {
userCity = readCookie ("user_city");
if (userCity)
{
window.location.replace(userCity + ".html");
}
else
{
window.location.replace("index.html");
}
}
function setCity(box) {
{
var userCity =(document.welcomeSignUp.userCity);
for (i=0; i<userCity.length; i++) {
if (userCity[i].name != box.name) {
userCity[i].selectedIndex = 0;
}
}
}
writeCookie("user_city", userCity, 5 * 365);
}
</script>
<link type="text/css" rel="stylesheet" href="style.css" />
</head>
<body>
<form id="welcomeSignUp" action="" method="get" name="welcomeSignUp" onload="redirect();">
Your Email address: <input type="text" name="email" value="" size ="20" />
<br />
Choose Your City: <select name="userCity" size="20">
<option value="one">Calgary</option>
<option value="two">Toronto</option>
<option value="three">Vancouver</option>
</select>
<a href="index.html"><button class="rounded" onclick="setCity(this);">
<span>submit form</span>
</button></a>
</form>
</body>
</html>
The form's drop down menu includes three cities (Calgary, Toronto, Vancouver). When the user presses "submit form", the script should create a cookie to store the user's city selection. Next time the user visits the site, they should be redirected to their city's site, ie. "/vancouver.html"
Right now, the code is returning an error from the onload("redirect();") function. The error indicates I am trying to redirect to "/[object HTMLSelectElement].html", but I am not sure if the trouble is in reading or writing the cookie. For simplicity, I've removed most of the other content from this page (my cookie.js is attached as a .doc):
<title>Site Title</title>
<script type="text/javascript" src="cookie.js"></script>
<script language="JavaScript" type="text/javascript">
function redirect() {
userCity = readCookie ("user_city");
if (userCity)
{
window.location.replace(userCity + ".html");
}
else
{
window.location.replace("index.html");
}
}
function setCity(box) {
{
var userCity =(document.welcomeSignUp.userCity);
for (i=0; i<userCity.length; i++) {
if (userCity[i].name != box.name) {
userCity[i].selectedIndex = 0;
}
}
}
writeCookie("user_city", userCity, 5 * 365);
}
</script>
<link type="text/css" rel="stylesheet" href="style.css" />
</head>
<body>
<form id="welcomeSignUp" action="" method="get" name="welcomeSignUp" onload="redirect();">
Your Email address: <input type="text" name="email" value="" size ="20" />
<br />
Choose Your City: <select name="userCity" size="20">
<option value="one">Calgary</option>
<option value="two">Toronto</option>
<option value="three">Vancouver</option>
</select>
<a href="index.html"><button class="rounded" onclick="setCity(this);">
<span>submit form</span>
</button></a>
</form>
</body>
</html>