I am new to Cookies and I just want to learn how to create and read a cookie! So I am getting help from http://www.w3schools.com/js/js_cookies.asp But the problem is I just want to create a simple cookie first and then read it! My code is:
<!DOCTYPE html>
<html>
<head>
<script>
function make(){
document.cookie="username=hellocookie";
}
function read(){
var x = document.cookie;
alert(x);
}
</script>
</head>
<body >
<button type="button" onclick="make()">make</button>
<button type="button" onclick="read()">read</button>
</body>
</html>
So The Link says:
document.cookie="username=hellocookie";
will create a cookie for me! so I created like this. The link also says to read all cookies at once I can use:
var x=document.cookie;
So it will return me all cookies!
My problem is that when I use document.cookie to return its value and show it in an alert. My alert shows nothing to me! is it me doing something wrong or something else? I just want to get the cookie I created! (I don't want to use expiry just need to do simple things work first)
Please something help me!