View Full Version : Cookie Drop

Apr 30th, 2003, 12:08 PM
Hi everyone and thanks for taking the time to check this out.

I have a nifty little script that shows/hides content on a single page when an image is clicked, which I have included below.

I am trying to set a cookie that will remember the user's last view (shown/hidden) when they return to the page.

I have never dropped a cookie so I am starting from scratch. I will do some research on this, but of course I need to get this going ASAP so I thought I'd ask the experts in hopes of saving time and learning something.

Thanks so much for your help.





td {
font-family : verdana;
font-size : 11px;

<script language="JavaScript">
function toggleElement(szId) {
var el = document.getElementById ? document.getElementById(szId) : document.all ? document.all[szId] : null;
if (! el) return;
el.style.display = el.style.display == "none" ? "block" : "none";
var theimage=document.getElementById('Image1').src;
if (theimage=="http://www.geocities.com/dominickpagano/close.gif") {document.getElementById('Image1').src="http://www.geocities.com/dominickpagano/open.gif"}
if (theimage=="http://www.geocities.com/dominickpagano/open.gif") {document.getElementById('Image1').src="http://www.geocities.com/dominickpagano/close.gif"}

function showStuff(){
var showStuff = ""
showStuff += "<table bgcolor=838383 border=0 cellpadding=5 cellspacing=0 width=150>"
showStuff += "<tr>"
showStuff += "<td><input type=image src=http://www.geocities.com/dominickpagano/close.gif onClick=toggleElement('data') name=Image1 id=Image1></td>"
showStuff += "</tr>"
showStuff += "</table>"

showStuff += "<table border=0 bgcolor=e0e0e0 cellpadding=10 cellspacing=0 id=data style=display:show; width=150>"
showStuff += "<tr>"
showStuff += "<td align=center>Expanded view</td>"
showStuff += "</tr>"
showStuff += "</table>"

if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) <= 4){
document.write("Sorry, IE or NN 6 only.");
else {



<div align="center">

<script language="javascript">
// -->

<table border=0 bgcolor=838383 cellpadding=0 cellspacing=0 width=150>


Apr 30th, 2003, 01:48 PM
There are many setCookie/getCookie functions already written. Mine is on the "Samples of my work > Cookies" page at:


Apr 30th, 2003, 02:25 PM

Thanks so much for your reply. I've done some reading and understand how to set and retrieve a simple cookie. My problem now lies in figuring out how to:

1) Set a value for the current state (open/closed) upon exit

2) Retrieve that value and restore the state upon return



Apr 30th, 2003, 02:30 PM
Using the functions on my site:

&nbsp;SetCookie('state', 'condition', '', 30);

&nbsp;condition = GetCookie('state');