A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Redirect cookie

  1. #1
    // Silent Protagonist ivanthem's Avatar
    Join Date
    Jul 2003
    Location
    New Zealand
    Posts
    295

    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">&nbsp; Go to page 2<br>
    <input type=radio name="option1" onClick="SetCookie('page', this.name, exp);" value="ON">&nbsp; Go to page 1</font></font><br>
    </td></tr>
    </table>
    </form>
    </center>

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    shouldn't two <input type=radio> have the same name but different values?

    Musicman

  3. #3
    // Silent Protagonist ivanthem's Avatar
    Join Date
    Jul 2003
    Location
    New Zealand
    Posts
    295
    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!

  4. #4
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    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

  5. #5
    // Silent Protagonist ivanthem's Avatar
    Join Date
    Jul 2003
    Location
    New Zealand
    Posts
    295
    You're right-
    Thanks a lot!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center