Saving data with cookies

Hi,

I’m working on a webpage that has drag-and-drop tabular data. I built the page with html/css (I don’t know how to program or use a database) and uses jQuery for the drag-and-drop feature. Is there a way that I could use cookies to save the data each time it is changed via drag-and-drop?


function setCookie(c_name, value, expiredays) {
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value)+
  ((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name) {
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1) {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

Those two functions will allow you to save and load a cookie. However, you will need to keep in mind that cookies are not limitless storage devices – you can hold approximately 4K of data per cookie. Also, cookies are sent up to the server in the header of each request, and some web servers may return an error if your header size exceeds a preset amount, so you don’t want to just keep adding additional 4K cookies.