Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
56
rated 0 times [  58] [ 2]  / answers: 1 / hits: 32814  / 13 Years ago, tue, january 31, 2012, 12:00:00

It must have been 15 years since I set a cookie value with javascript ...



document.cookie = 'key=value';  //got that ...


How do I append another value with the same key? I want to create a list of values (page=1,34,48,59...) that I can then read and loop over. Or is there a better way?


More From » cookies

 Answers
275

Specify them all once eg:



var value = ['1', '2', '3', 'n'].join(',');
document.cookie = 'key=' + value;


where 'key=' + value will now be:



key=1,2,3,n


Or alternatively, read your data from cookie first and add new data:



var keycookie = // read your cookie here
keycookie += 'new stuff';
document.cookie = 'key=' + keycookie;

[#87720] Sunday, January 29, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sandra

Total Points: 708
Total Questions: 100
Total Answers: 84

Location: Bosnia and Herzegovina
Member since Thu, Jun 24, 2021
3 Years ago
sandra questions
Tue, Jun 30, 20, 00:00, 4 Years ago
Sun, May 31, 20, 00:00, 4 Years ago
Wed, May 20, 20, 00:00, 4 Years ago
Fri, May 31, 19, 00:00, 5 Years ago
;