Home › Forums › Bee WordPress Theme › Checkboxes with js cookies
- This topic has 3 replies, 2 voices, and was last updated 11 years ago by
SeaTheme.
-
AuthorPosts
-
August 29, 2015 at 6:06 pm #8205
Filipemus
ParticipantHi,
I am trying to include checkboxes that store the user input through cookies. It’s a simple code with js, but it doesn’t work when I use it in a page. It works when I try it on an online html editor. What can be the conflict?
Here is the code:
<div>
<label for=”checkAll”>Check all</label>
<input type=”checkbox” id=”checkAll”>
</div>
<div>
<label for=”option1″>Option 1</label>
<input type=”checkbox” id=”option1″>
</div>
<div>
<label for=”option2″>Option 2</label>
<input type=”checkbox” id=”option2″>
</div>
<div>
<label for=”option3″>Option 3</label>
<input type=”checkbox” id=”option3″>
</div><script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js”></script>
<script src=”http://cdn.jsdelivr.net/jquery.cookie/1.4.0/jquery.cookie.min.js”></script><script>
$(“#checkAll”).on(“change”, function() {
$(‘:checkbox’).not(this).prop(‘checked’, this.checked);
});$(“:checkbox”).on(“change”, function(){
var checkboxValues = {};
$(“:checkbox”).each(function(){
checkboxValues[this.id] = this.checked;
});
$.cookie(‘checkboxValues’, checkboxValues, { expires: 7, path: ‘/’ })
});function repopulateCheckboxes(){
var checkboxValues = $.cookie(‘checkboxValues’);
if(checkboxValues){
Object.keys(checkboxValues).forEach(function(element) {
var checked = checkboxValues[element];
$(“#” + element).prop(‘checked’, checked);
});
}
}$.cookie.json = true;
repopulateCheckboxes();
</script>August 30, 2015 at 7:11 am #8206Please leave your page url
September 1, 2015 at 2:43 pm #8221Filipemus
ParticipantThis reply has been marked as private.September 2, 2015 at 2:00 am #8230I checked your page, there are some issue:
TweenMax.min.js?ver=1.14.2:14 Uncaught TypeError: Cannot read property ‘push’ of undefined
Try to stop all plugins and test again.
-
AuthorPosts
- You must be logged in to reply to this topic.
