SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Storing checkbox Cookie

    hi,
    I have a little problem here. I know how to create cookies etc.. I've got to the point where the checkbox is stored in a cookie. But how can i make it so that when the checkbox is checked and the person leaves the page, when they come back i need the checkbox to still be checked(ticked) instead of blank (the checkbox being ticked will run a function to do something else..).

    do i need an if statement? how would i do this? is this right?
    if(cookie is set){
    make the checkbox checked
    }

    Thanks for any help

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    A simple if statement should work fine

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,139
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    The only code I hate more than my own is everyone else's.

  4. #4
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    myForm.myCheckbox.checked = !!readCookie( 'myCookie' );
    Tab-indentation is a crime against humanity.


Bookmarks

Posting Permissions

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