-5

In that case, I put 1 2 3 in each input and it only shows number 3. How can I fix it? I'm sorry if it's a stupid question but I really don't know.

function WriteCookie()
{
    cookievalue= document.myform.firstname.value+";";
    cookievalue1= document.myform.memory.value+";";
    cookievalue2= document.myform.half.value+";";
    cookievalue3= document.myform.lose.value+";";

    document.cookie=cookievalue;
    document.cookie=cookievalue1;
    document.cookie=cookievalue2;
    document.cookie=cookievalue3;

    alert(document.cookie);
}
april
  • 1
  • 1
  • All the values that you got you assigned it to `document.cookie`. – Pritam Banerjee Sep 11 '17 at 06:36
  • 1
    it only shows 3 because that's the last value assigned to the variable "cookie" and/or your not using a proper key-value pair for your cookie, I suggest you read up on how variables work. You also need to understand how Javascript cookies work, read this for more information https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie – Keith M Sep 11 '17 at 06:36
  • Possible duplicate of [How do I create and read a value from cookie?](https://stackoverflow.com/questions/4825683/how-do-i-create-and-read-a-value-from-cookie) – sissy Sep 11 '17 at 07:24
  • I have read it but still don't understand, sorry...and when i changed it to document.cookie1,2,3 it worked and then I got a new problem it didn't show in another page.... so I changed it backs to document.cookie at least it shows the value but the wrong one – april Sep 11 '17 at 11:19

1 Answers1

1

You rewrote document.cookie 4 times with a new value each time.

If you'd like to combine data from all 4 vars uses code like:

function WriteCookie()
{
    var cookievalue = document.myform.firstname.value+";";
    var cookievalue1 = document.myform.memory.value+";";
    var cookievalue2 = document.myform.half.value+";";
    var cookievalue3 = document.myform.lose.value+";";
   
    cookievalue = cookievalue + cookievalue1 + cookievalue2 + cookievalue3;
    
    document.cookie = cookievalue;
    

    alert(document.cookie);
}
zhuravlyov
  • 503
  • 2
  • 11
  • I did as you write but now it only shows the first one – april Sep 11 '17 at 07:30
  • Please thy this: function WriteCookie() { var cookievalue = 'a'; var cookievalue1 = 'b'; var cookievalue2 = 'c'; var cookievalue3 = 'd'; cookievalue = cookievalue + cookievalue1 + cookievalue2 + cookievalue3; document.cookie = cookievalue; alert(document.cookie); } WriteCookie(); and you'll get abcd – zhuravlyov Sep 11 '17 at 07:36
  • I have to show the values that put in the boxes. I can't do like that. it's not specific value – april Sep 11 '17 at 07:41
  • it's too long can't send here, how can I send it to you? – april Sep 11 '17 at 09:04
  • just upload your files to any host & I'll help you – zhuravlyov Sep 11 '17 at 09:07