Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Need help with cookie background function..

Author
Message
Mugen Wizardry
User Banned
Posted: 18th May 2009 22:43
Hi all I've been researching cookies a bit, and I attempted to create a function that if you select a background name from a drop down list or anything for that matter, it will save the background in the cookie, and display it in a div background for later use. Now I can't quite figure out why there is a problem with this script, but the error checker tells me there is.

Heres the code:



ANY help is GREATLY appreciated!

Thanks!

~SI~
gbark
19
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 19th May 2009 19:12
I tried running that in a page, and it didn't throw up any error messages for me. I copied your code as-is, so maybe you're getting a JavaScript error from another part of your page?
AlexI
20
Years of Service
User Offline
Joined: 31st Dec 2004
Location: UK
Posted: 19th May 2009 19:59
I would use PHP, you could do that a lot quicker then

Mugen Wizardry
User Banned
Posted: 19th May 2009 20:09
Ok. this works. i redid the data functions. the only prob is, when i leave and come back to the same page, or refresh, it doesnt save the background.. even though the cookie is correct, as u can use alert(GetCookie('image')); to see.

Here's the code:



Thanks!

~SI~

PS. I cannot use php cuz im working on this site for my dad, and he needs to edit it with frontpage.
gbark
19
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 19th May 2009 20:51
You need to add an expiration date to your cookies when you set them. If you don't set one, the cookie is cleared next time you restart your browser.

One easy way to do this is just to default each cookie to expire in one year:

Mugen Wizardry
User Banned
Posted: 19th May 2009 22:40
thanks but if u read my code, ud know i already have an expiration date code on it.

can somebody else please help?

ANY help is GREATLY appreciated!
Mugen Wizardry
User Banned
Posted: 21st May 2009 01:07
Ok. I have the fixed function. And as said before, I have done lots of research on cookies, and have tried just about every algorithm in the book, and to no avail.

Here's the new code, the only prob is I need to use an array and select box, so depending on what is selected, it will change and save the background using that image, and because it is saved, depending on what image was used, will display that pic using a cookie.

Here's the code:

Ok. I have 1 more small question. Then this is complete

How do I use an array and an if function to tell thefinal variable which picture to display depending on what is selected, and save the selected image value to the cookie using saveImage() ?

heres the code:



Thanks again for all your support!

~SI~

Login to post a reply

Server time is: 2025-06-02 10:00:32
Your offset time is: 2025-06-02 10:00:32