Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    23
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Question need help with cookies

    hi first post dunno if it is in the right place

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

    Code:
    <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.

    Code:
    <img src="pictures/ !!!output!!! /something.png">
    so far i have this (just a trial)

    Code:
    <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

  • #2
    New Coder
    Join Date
    Mar 2009
    Posts
    23
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Any help ????

  • #3
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Try:
    Code:
    function image() {
    	settings=getCookie('settings');
    	if (settings!=null && settings!="")
    		return '<img src="'+settings+'.png">';
    }
    document.write(image())
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • Users who have thanked rangana for this post:

    rhyz (03-13-2009)

  • #4
    New Coder
    Join Date
    Mar 2009
    Posts
    23
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Thankyou worked

    so happy

    thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •