The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> trying to hide a html table with javascript with cookie support
steve51184
post Feb 25 2009, 09:38 PM
Post #1





Group: Members
Posts: 1
Joined: 25-February 09
Member No.: 7,899



hey all i'm trying to hide a html table with javascript with cookie support but can't get the show/hide button to work.. here's what i have so far:

CODE
<html>
<head>
</head>
<body>
<script type="text/javascript">

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}


function eraseCookie(name) {
    createCookie(name,"",-1);
}

function tableIsVisible(){ return readCookie("showtable")=="true"; }
function toggleCookie(){ if(readCookie("showtable") == "false") createCookie("showtable","true",365*60*24*10); else createCookie("showtable","false",65*60*24*10); }

function displayRow(show){
var row = document.getElementById("captionRow");
if (show=="false") row.style.display = 'none';
else row.style.display = '';
}

displayRow(tableIsVisible());

</script>
<table width="300" border="1" id="captionRow">
<tr><th>TH-1</th><th>TH-2</th><th>TH-3</th></tr>
<tr><td>cell-11</td><td>cell-12</td><td>cell-13</td></tr>
<tr><td>cell-21</td><td>cell-22</td><td>cell-23</td></tr>
</table>
<p><button onclick="toggleCookie(); displayRow(tableIsVisible());" >Show / Hide</button></p>
</body>
</html>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 16th December 2018 - 11:27 AM