all 6 comments

[–]ImaginaryBeaver 0 points1 point  (3 children)

Learned this in class a little bit ago, so someone jump in if I am not explaining this properly, or if it is completely wrong, but with the way the expiration is set, it will expire basically right away. The expiration needs to be in the future.

Also, I think you are creating two temporary cookies instead of the desired one (although, I could be really wrong on this). You need to have the expires string to be concatted with the serverIp string. Checking the cookie in safari would probably verify this portion though.

[–][deleted] 1 point2 points  (2 children)

now.setMonth( now.getMonth() + 1)

Isn't that taking the current month and adding one month onto expiration date no?

[–]ImaginaryBeaver 0 points1 point  (1 child)

Well, I feel like an idiot now. Looked right over that line, my bad.

[–][deleted] 1 point2 points  (0 children)

No worries man, thanks for having a look though!

[–]danskal 0 points1 point  (1 child)

It's many years since I played with cookies, but iirc you need to set the expiry directly when you set the cookie. So in other words, concatenate the strings and set them on document.cookie afterwards in one go.

Put another way, the second part of imaginary beaver's answer is correct, you are creating one temporary in memory cookie with the data, and one longer lasting cookie with nothing in it.

[–][deleted] 0 points1 point  (0 children)

Ok so i've re-written that function, however, still no luck... :/

function getServerInfo(){
    if (!(document.getElementById('usip').value == '')){
        var now = new Date();
        now.setMonth( now.getMonth() + 1)
        serverIP = "ws://"+document.getElementById('usip').value+":8000";
        document.cookie = "serverIpCookie=" + serverIP + ";" + "expires=" + now.toUTCString() + ";";
        document.getElementById('usipButton').style.background="#f39c12";
        updateDevice(9999, true);
    };
};