-
Redirect cookie
Hi,
Here is the code for my redirection script- but I have one problem- I can't get the script to make only 1 radio button selectable. Please help!
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : TRUE;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var favorite = GetCookie('animal');
if (favorite != null) {
switch (favorite) {
case 'option1' : url = 'page1.htm';
break;
case 'option2' : url = 'page2.htm';
break;
}
window.location.href = url;
}
</script>
<center>
<form>
<table width="168"><tr><td width="162">
<font size="1" face="Verdana">
<input type=radio name="option1" onClick="SetCookie('page', this.name, exp);" value="ON"><font color="#FFFFFF"> Go to page 2<br>
<input type=radio name="option1" onClick="SetCookie('page', this.name, exp);" value="ON"> Go to page 1</font></font><br>
</td></tr>
</table>
</form>
</center>
-
Hi,
shouldn't two <input type=radio> have the same name but different values?
Musicman
-
I tried that but all I got was 'Do you want to debug?'.
Do you know of any other way of doing this or a site that shows how?
Thanks!
-
Hi,
it works much better with these two lines changed:
<input type=radio name="page" onClick="SetCookie('animal', this.value, exp);" value="option1"><font color="#FFFFFF"> Go to page 1<br>
<input type=radio name="page" onClick="SetCookie('animal', this.value, exp);" value="option2"> Go to page 2</font></font><br>
My browser did not really want me to debug, but it did not like the uppercase TRUE in the SetCookie function
Musicman
-
You're right-
Thanks a lot!