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

Related Questions

This function is written twice to save the checkbox state as well as the
i am using custom checkbox buttons in my table view and want to save
I need to know if is possible to save the state of a CheckBox
I want to save the state of a multiple choice listview checkbox's. I have
Can someone instruct me how to save the state of the checkbox's of a
i am using SharedPreferences in my code that will store last state of my
I am using asp.net and I am trying to save checkbox values into a
I would like to save multiple checkbox(PHP and JQuery) in to MYSQL database. Example
This Run like it is perfectly fine. // Save, set state to finalized and
I have been trying to use/save the boolean value of a checkbox in other

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.