jotgabbi Posted October 20, 2009 Share Posted October 20, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/178315-populating-dropdown-with-cookie-contents/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.