Skip to content

Instantly share code, notes, and snippets.

@EminenceHC
Created November 14, 2013 18:50
Show Gist options
  • Save EminenceHC/7472270 to your computer and use it in GitHub Desktop.
Save EminenceHC/7472270 to your computer and use it in GitHub Desktop.
Remember checkbox state.
<div class="well">
<p><input type="checkbox" name="basic" class="box" /> Basic</p>
<p><input type="checkbox" name="address" class="box" /> Address</p>
<p><input type="checkbox" name="phone" class="box" /> Phone</p>
</div>
$(document).on('ready page:load', function(){
$("input.box").each(function() {
var mycookie = $.cookie($(this).attr('name'));
if (mycookie && mycookie == "true") {
$(this).prop('checked', mycookie);
}
});
$("input.box").change(function() {
$.cookie($(this).attr("name"), $(this).prop('checked'), {
path: '/',
expires: 365
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment