Reputation: 1080
I created a simple page that lets you make cookies and displays them by appending them to a text area. My understanding is that you can create as many cookies as you want simply by calling
document.cookie = ...
However, when I print out my cookies, only 3 of them are ever displayed. It also appears that I'm not appending the cookies to the text area properly, because these values never change.
To test if this was a problem with the cookie creation, I used an alert popup box to notify the user when their new cookie is created. This shows me that the cookies ARE being created. So, I don't know why I can only see three of the cookies in the display.
Here is the code:
EDIT: code removed because answer is closed.
How can I fix this so that all the cookies created are appended to the text area? Thanks.
Upvotes: 1
Views: 5226
Reputation: 79
When you set a cookie via document.cookie you provide a key\value pair in the form key=value.
In your code you are always passing a key of "name" so rather then creating a new cookie you're just updating the same cookie every time. You need to find a way to generate a unique identifier to use as the key for each new cookie (perhaps a count will do)
Also you shouldn't need to append the value from document.cookie to the text as document.cookie will return the values for all cookies so you can just set the value of document.cookie to the value of you text area.
Upvotes: 2