I am trying to set a cookie with the onclick of a button. I am still very new to cookies and I am not sure what I am doing wrong. Below is the button and the function.
<script type="text/javascript">
function setCookie(){
var exp = new Date( );
exp.setMinutes( exp.getMinutes( ) + 5 );
document.cookie("cookieOne=red; expires=" + exp.toUTCString( ));
}
</script>
<input name="addtocart" type="button" value="Add To Cart" onClick="setCookie()" />
I thought this would work but when I go to another page it prints nothing. Here is the second page.
<link href="css/mainstyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="Table_01">
<script type="text/javascript">
document.writeln( document.cookie );
</script>
</div>
</body>
</html>
Again I just hit the cookies section of the javascript book I am learning from and this simple test doesnt seem to be working for me.
Try adding
;path=/and see if it fixes things.EDIT: whoops, nothing to see, move along…