Make cookie using Javascript : Cookie « Development « JavaScript Tutorial






<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
<!--
expireAt = new Date;
expireAt.setMonth(expireAt.getMonth() + 3);
username = "";

function makeCookie()
{
    username = document.form1.user1.value
    document.cookie = "name=" + username + ";expires=" + expireAt.toGMTString()
}
//  -->
</script>
</head>
<body>
<form name="form1">
<P>Username: <input type="text" name="user1"><br>
<a href="http://www.java2s.com" onclick="makeCookie()">continue ...</a></p>
</form>
</body>
</html>








4.4.Cookie
4.4.1.JavaScript and Cookies
4.4.2.Reading Cookies
4.4.3.Writing Cookies
4.4.4.Create a cookie and read it back
4.4.5.Make cookie using Javascript
4.4.6.Delete all cookies
4.4.7.Read cookie value