<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>