I am new in JS and I don't know why my following code is not correct, I want just to set a cookie when the user click over the check box and to delete the cookie when the user uncheck the box:
<script type="text/jscript">
function myCookie(){
if (this.checked == true) {
setCookie(this.name, this.id, '', '25 Dec 2020');
}
else {
document.cookie = this.id + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
}
}
</script>
<form method="post" name="form1">
<input id="one" name="Checkbox1" type="checkbox" onchange="myCookie()" /> Cat<br />
<input id="two" name="Checkbox2" type="checkbox" onchange="myCookie()" /> Dog<br />
<input id="three" name="Checkbox3" type="checkbox" onchange="myCookie()" /> Gerbil<br />
<input id="four" name="Checkbox4" type="checkbox" onchange="myCookie()" /> Gopher<br />
</form>
this is the http://ift.tt/1HKaw17
Aucun commentaire:
Enregistrer un commentaire