HTML code
HTML Code:
<input type="text" name="name" class="cookie" value="" />
<input type="text" name="password" class="cookie" value="" />
<input type="text" name="email" class="cookie" value="" />
<input type="text" name="message" value="" />
<textarea name="address" class="cookie"></textarea>
JS Code
Code:
$(function(){
var prefix = 'cook';
$('.cookie')
.each(function(){
if(!$(this).val()){
$(this).val(getCookie(prefix+$(this).attr('name')))
}
})
.change(function(){
if($(this).val()){
setCookie(prefix+$(this).attr('name'),$(this).val(),365);
}else{
deleteCookie(prefix+$(this).attr('name'));
}
// alert(document.cookie);
})
})
1. Fields you want to cache will have class="cookie" and MUST HAVE a distinct name attribute
2. Input and textarea elements are accepted
3. I used jQuery and cookie functions (setCookie, getCookie, deleteCookie)
from http://jquery-howto.blogspot.com/201...te-plugin.html
4. Use any value for prefix. It's just a precaution to not overwrite other useful cookies.
5. As you can see, input name="message" does not have class="cookie". Value for this field will not be cached.
Bookmarks