jQuery++ - jQuery.cookie demo

A demo for jQuery.cookie. Change the form to save it to a cookie or reload it.

by donejs

HTML

<script src="http://jquerypp.com/release/latest/jquerypp.js"></script>
<form>
    <p><label>Your name</label><input type="text" name="name" /></p>
    <p><label>Email</label><input type="text" name="email" /></p>
    <p><input type="checkbox" name="newsletter" /><label>Newsletter</label></p>
    <p><input type="checkbox" name="updates" /><label>Updates</label></p>
</form>

<button id="save">Save to cookie</button>
<button id="load">Load from cookie</button>

<p>URI encoded cookie looks like:</p>
<p id="cookie"></p>

CSS

body {
    font-family: Verdana;
}

p {
    margin: 10px 0;
}

#cookie {
    color: #505050;
}

label {
    display: block;
    float: left;
    width: 100px;
}

JavaScript

function showCookie() {
    $('#cookie').html(decodeURIComponent(document.cookie));
}

showCookie();

$('#save').click(function() {
    $.cookie('form', $('form').formParams());
    showCookie();
});
$('#load').click(function() {
    $('form').formParams($.cookie('form'));
}).click();