https://github.com/wellwind/cookie-checkbox
Save cookie data when checkbox checked, or load cookie data to checkbox when page load.
https://github.com/wellwind/cookie-checkbox
Last synced: about 1 year ago
JSON representation
Save cookie data when checkbox checked, or load cookie data to checkbox when page load.
- Host: GitHub
- URL: https://github.com/wellwind/cookie-checkbox
- Owner: wellwind
- Created: 2015-06-10T01:22:02.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-06-10T01:46:48.000Z (about 11 years ago)
- Last Synced: 2024-10-12T06:35:36.464Z (over 1 year ago)
- Language: JavaScript
- Size: 133 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cookie-checkbox
Save cookie data when checkbox checked, or load cookie data to checkbox when page load.
See demo here: http://wellwind.github.io/cookie-checkbox/demo.html
## Installation
```HTML
```
You can get jquery.cookie plugin here:
https://github.com/carhartl/jquery-cookie
## Usage
### Step 1. Set data-checkbox-* data-api to checkbox
All cookie checkbox shoud add data-checkbox-* data-api.
You need to set `data-cookie-checkbox="true"` to enable a cookie checkbox, then set `data-cookie-check-box-key="{key}"` and `data-cookie-checkbox-value="{value}"`.
```HTML
Option 01
Option 02
```
When check or uncheck the checkbox the {value} will be added or removed from cookie {key} (cookie name will be cookie-checkbox-{key}).
If you want a checkbox for check all. You can set `data-cookie-checkbox-check-all="true"` and `data-cookie-checkbox-key="{key}"` to a checkbox.
```HTML
Select All
```
When this check box check or uncheck, all checkboxes with same {key} will be checked / unchecked.
### Step 2. Use javascript to enable cookie checkbox
When page load, you need to call `enableCookieCheckBox();` to enable cookie checkbox.
```javascript
$(document).ready(function() {
enableCookieCheckBox();
});
```
You can call `getCookieCheckboxValues('{key}')` to get the values checked.
```javascript
var result = JSON.stringify(getCookieCheckboxValues('CookieCheckBoxSample1'));
alert(result);
```
If you want to clear the cookie checkbox values stored to cookie, juse call `clearCookieCheckBox('{key}')`