Jump to content

Populating dropdown with cookie contents


jotgabbi

Recommended Posts

Hi

Using very helpful code found on these forums, I want to be able to have a table with dynamic contents, and allow the ability to hide and show columns. The only way I could think of doing this was to have each column as a div and separate table essentially, then you could hide/show each div.

 

<script type="text/javascript">

function toggleList(id, displayValue) {
    var obj = document.getElementById(id);
    if(!displayValue)
    {
        var displayValue = (obj.style.display!='none')?'none':'block';
    }
    obj.style.display = displayValue;
    setCookie(id, displayValue, 30); 
    return;
}

window.onload = function()
{
    toggleList('start', getCookie('start'));
    toggleList('finish', getCookie('finish'));
    toggleList('time', getCookie('time'));
toggleList('distance', getCookie('distance'));
toggleList('speed', getCookie('speed'));
toggleList('rushhour', getCookie('rushhour'));
toggleList('night', getCookie('night'));
toggleList('motorway', getCookie('motorway'));
toggleList('rural', getCookie('rural'));
toggleList('urban', getCookie('urban'));
    return;
}

function setCookie(name, value, expiredays)
{
    if (expiredays==null) { expiredays=0; }

    var expireDate = new Date();
    expireDate.setDate(expireDate.getDate()+expiredays);

    var cookieVal  = name + '=' +escape(value) + ';expires=' + expireDate.toGMTString();
    document.cookie = cookieVal;
    return;
}

function getCookie(searchName)
{
  if (document.cookie.length>0)
  {
    var nameValuePair, cookieName, cookieValue
    var pairs = document.cookie.split(';');
    for(var i=0; i<pairs.length; i++)
    {
      nameValuePair = pairs[i].split('=');
      cookieName    = nameValuePair[0].replace(/^\s+|\s+$/g,'');
      cookieValue   = nameValuePair[1].replace(/^\s+|\s+$/g,'');
      if(cookieName == searchName) { return cookieValue; }
    }
  }
  return false;
}

</script>

 

Is there anyway, that the divs that are hidden, with preferences saved into a cookie, could be inserted into a dropdown, allowing them to click and add the column back to the table.

 

Any ideas?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.