...

View Full Version : need help with cookies



rhyz
03-12-2009, 11:28 AM
hi first post dunno if it is in the right place

i use javascript to create a cookie when you click a link



<a href="#" onclick="document.cookie='settings=blue; expires=31/03/2009;'">Blue</a>


this creates a cookie and i can get it back easily

but i want to use it as settings

i have 3 folders of pictures white blue and pink the user will click the link selecting there colour creating a cookie

now when the page finds the cookie it needs to place the output in to the path.



<img src="pictures/ !!!output!!! /something.png">


so far i have this (just a trial)



<script type="text/javascript" src="cookie.js">
</script>
<script type="text/javascript">

function image()
{
settings=getCookie('settings');
if (settings!=null && settings!="")
{
document.write('<img src="'+settings+'.png">')
}
}
document.write(image())
</script>

this works but next to the image it says undefined so how would i get rid of it?
and i was wondering if there was a better way to do it??

THANKS :thumbsup:

rhyz
03-12-2009, 12:39 PM
Any help ????

rangana
03-12-2009, 04:57 PM
Try:


function image() {
settings=getCookie('settings');
if (settings!=null && settings!="")
return '<img src="'+settings+'.png">';
}
document.write(image())

rhyz
03-13-2009, 01:34 PM
Thankyou worked :)

so happy :):):):):)

thanks :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum