I tried but I can able to set only one cookie with my code...it needs some alteration only. I need to set cookies for the remain checkboxes too...how to do it in generic model using
$(document).ready(function() {
ReadCookie();
});
function setCookie(c_name, value) {
document.cookie = c_name + "=" + value;
}
function set_check() {
setCookie('Cookie1', document.getElementById('cookie_setter').checked ? 1 : 0);
ReadCookie();
}
function ReadCookie() {
var allcookies = document.cookie;
// Get all the cookies pairs in an array
cookiearray = allcookies.split(';');
// Now take key value pair out of this array
for (var i = 0; i < cookiearray.length; i++) {
name = cookiearray[i].split('=')[0];
value = cookiearray[i].split('=')[1];
console.log("Key is : " + name + " and Value is : " + value);
if (value == "1") {
console.log(value);
document.getElementById('cookie_setter').checked = true;
}
}
}
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.js"></script>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div style="max-width:980px;margin:0 auto;">
<input type="checkbox" name="vehicle" id="cookie_setter" onchange="set_check();">Cookie1
<br>
<input type="checkbox" name="vehicle" value="Car">Cookie2
<br>
<input type="checkbox" name="vehicle" value="Car">Cookie3
</div>
</body>
</html>