Really easy help (Cookies)
Posted: Wed May 06, 2009 3:07 pm
Okay, I have a page where sections are shown and hidden when a link is clicked.
What I want is to be able to save which sections visitors have open, and which they have closed, and I decided cookies was the best bet.
Here is the code, it is mainly Javascript / HTML currently, with PHP at the top.
Any help would be greatly appreciated.
What I want is to be able to save which sections visitors have open, and which they have closed, and I decided cookies was the best bet.
Here is the code, it is mainly Javascript / HTML currently, with PHP at the top.
Any help would be greatly appreciated.
Code: Select all
<?php
$expire=time()+60*60*24*30;
setcookie("para1", "$1", $expire);
?>
<html><head><title>Show / hide testing</title></head>
<body><script type="text/javascript">
function displayPara(fieldID, displayBol) {
var paraObj = document.getElementById(fieldID);
var showObj = document.getElementById(fieldID+'_show');
var hideObj = document.getElementById(fieldID+'_hide');
paraObj.style.display = (displayBol)? '' : 'none' ;
showObj.style.display = (!displayBol)? '' : 'none' ;
hideObj.style.display = (displayBol)? '' : 'none' ;
}
</script>
<a href="#" onclick="displayPara('para1', false);" id="para1_hide" style="display:none;">Hide</a>
<a href="#" onclick="displayPara('para1', true);" id="para1_show" style="">View</a>
<div id="para1" style="display:none;">1st paragraph of text</div>
<a href="#" onclick="displayPara('para2', false);" id="para2_hide" style="display:none;">Hide</a>
<a href="#" onclick="displayPara('para2', true);" id="para2_show" style="">View</a>
<div id="para2" style="display:none;">2nd paragraph of text</div>
<a href="#" onclick="displayPara('para3', false);" id="para3_hide" style="display:none;">Hide</a>
<a href="#" onclick="displayPara('para3', true);" id="para3_show" style="">View</a>
<div id="para3" style="display:none;">3rd paragraph of text</div>
</body></html>