0

Is it possible? I want to save the state of the radio.. like : enabled or disabled.

if(dis == "dis1"){document.getElementById(dis).disabled=true;}

This does not last till the code it completed.

Once it is disabled, I want it to be disabled till the code is completed!

Andy G
  • 19,232
  • 5
  • 47
  • 69
user3672971
  • 65
  • 1
  • 6

1 Answers1

0

Here is a really nice implementation

var createCookie = function(name, value, days) {
    var expires;
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toGMTString();
    }
    else {
        expires = "";
    }
    document.cookie = name + "=" + value + expires + "; path=/";
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) {
                c_end = document.cookie.length;
            }
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

So in your case

createCookie("radio", "checked/notchecked", 30);

and then to read it

getCookie("radio") === 'checked' or !== 'checked'

Source: How do I create and read a value from cookie? There are also some other solutions mentioned there, make sure you check them.

Community
  • 1
  • 1
FrEaKmAn
  • 1,785
  • 1
  • 21
  • 47