Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 947587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:06:15+00:00 2026-05-15T23:06:15+00:00

how do i save checkbox state through sessions? i’m using this jquery code to

  • 0

how do i save checkbox state through sessions? i’m using this jquery code to toggle the options:

$('div.check input:checkbox').bind('change',function(){
    $('#'+this.id+'txt').toggle($(this).is(':checked'));
});

but when i reload, the checkboxes are back to their default state. i know i’d have to use sessions, but how do i make the checkbox state persist using sessions in php?

html:

<div class="check">
<p><input type="checkbox" value="Name" id="name" checked /> <label for="name">Name</label></p>  
<p><input type="checkbox" value="Reference " id="reference" checked /> <label for="reference">Reference</label></p>
    </div>

    <div id="nametxt"> Show Name TEXT </div>
    <div id="reftxt"> Show Ref TEXT </div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:06:15+00:00Added an answer on May 15, 2026 at 11:06 pm

    Purely in JavaScript supporting localStorage if available, otherwise using document.cookie.

    function getStorage(key_prefix) {
        // this function will return us an object with a "set" and "get" method
        // using either localStorage if available, or defaulting to document.cookie
        if (window.localStorage) {
          // use localStorage:
          return {
            set: function(id, data) {
              localStorage.setItem(key_prefix+id, data);
            },
            get: function(id) {
              return localStorage.getItem(key_prefix+id);
            }
          };
        } else {
          // use document.cookie:
          return {
             set: function(id, data) {
               document.cookie = key_prefix+id+'='+encodeURIComponent(data);
             },
             get: function(id, data) {
               var cookies = document.cookie, parsed = {};
               cookies.replace(/([^=]+)=([^;]*);?\s*/g, function(whole, key, value) {
                  parsed[key] = decodeURIComponent(value);
               });
               return parsed[key_prefix+id];
             }
           };
         }
      }
    
    jQuery(function($) {
      // a key prefix is used for the cookie/storage
      var storedData = getStorage('com_mysite_checkboxes_'); 
    
      $('div.check input:checkbox').bind('change',function(){
        $('#'+this.id+'txt').toggle($(this).is(':checked'));
        // save the data on change
        storedData.set(this.id, $(this).is(':checked')?'checked':'not');
      }).each(function() {
        // on load, set the value to what we read from storage:
        var val = storedData.get(this.id);
        if (val == 'checked') $(this).attr('checked', 'checked');
        if (val == 'not') $(this).removeAttr('checked');
        if (val) $(this).trigger('change');
      });
    
    });
    

    jsFiddle demo available — Click some checkboxes, then “Run” the script again!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 536k
  • Answers 535k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Have not tried this but - in Project properties ->… May 17, 2026 at 1:15 am
  • Editorial Team
    Editorial Team added an answer You could do: y.ToList().ForEach(x => value = value.Replace(x, "")); Although… May 17, 2026 at 1:15 am
  • Editorial Team
    Editorial Team added an answer It's better to use master branch only for Production and… May 17, 2026 at 1:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

This function is written twice to save the checkbox state as well as the
<form> <input type=checkbox id=m_q name=m_q value=271>Name</input><div name=status></div> <input type=checkbox id=m_q name=m_q value=271>Age</input><div name=status></div> <input
I need a form width a checkbox Don't show this again for my winform,
as a follow up to this question , while the checkbox value is stored
how to triggered open/save window by using javascript?
I know that to save/restore matrix state you use standard push/pop operations. I haven't
I've got an activity with a search field with a near current location checkbox
this is my scenario: i have a page with a placeholder. the page adds
I'm a tad confused. I have a Repeater which populates a list of Checkbox
Please save my skin. http://clubentertainment.ie/c/art-perf/embed_example.html The above link should load in Firefox, doesn't load

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.