Question: I have a list of checkboxes, that I'd like, when clicked to be added to a cookie using jQuery.

My code is like:

```
<input type="checkbox" value="vat_50" name="vat_50" class="tax">
<input type="checkbox" value="vat_34" name="vat_50" class="tax">
<input type="checkbox" value="vat_12" name="vat_50" class="tax">

```

How would I set the cookie, for the checkboxes above?

I've seen `$.cookie`, but not sure how to implement it.

Thanks

Answer: 
Try this provided you using jquery cookie [plugin](http://plugins.jquery.com/files/jquery.cookie.js.txt)

```
$(document).ready( function() {

    $('input:checkbox').click(function() {
        var name = $(this).attr("name");
        var value = $(this).val();
        $.cookie(name, value, { expires: 365 });//Set the expires time as per your requirement.
    });
});

```
here is a simple library i hv written.. you dont need a bloated library.. just minify this

```
var cookieManager = (function () {
    return {
        createCookie: function (name, value, days) {
            var expires = "";
            if (days) {
                var date = new Date();
                date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
                expires = "; expires=" + date.toGMTString();
            }
            document.cookie = name + "=" + value + expires + "; path=/";
        },
        writeSessionCookie: function (cookieName, cookieValue) {
            document.cookie = cookieName + "=" + cookieValue + "; path=/";
        },
        readCookie: function (name) {
            var nameEq = name + "=";
            var ca = document.cookie.split(';');
            var i;

            for (i = 0; i < ca.length; i++) {
                var c = ca[i];
                while (c.charAt(0) === ' ') { c = c.substring(1, c.length); }
                if (c.indexOf(nameEq) === 0) { return c.substring(nameEq.length, c.length); }
            }

            return null;
        },
        deleteCookie: function (name) {
            this.createCookie(name, null, -1);
        }
    };
}());

```

usage.:

```
cookieManager.writeCookie("foo","bar");

var fooValue=cookieManager.readCookie("foo");

```