...

View Full Version : More than once



TaboTabo
02-25-2007, 06:01 PM
I have this script:

<Head>

<script type="text/javascript" language="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 hidemembers() {
toggleBox('members','none');
createCookie('members','none');
}

function showmembers() {
toggleBox('members','block');
createCookie('members','block');
}

function toggleBox(id, display) {
// DOM3 = IE5, NS6
if (document.getElementById) {
document.getElementById(id).style.display = display;
// Netscape 4
} else if (document.layers) {
document.layers[id].display = display;
// IE 4
} else if (document.all) {
document.all[id].style.display = display;
}
}

window.onload = function() {
var memberDisplay = readCookie('members');
if (memberDisplay !== null) {
toggleBox('members',memberDisplay);
}
};

</head>
<body>

<a href="javascript:showmembers()">Show</a> | <a href="javascript:hidemembers()">hide</a>

<div id="members">content1</div>
</body>

However i need to use the same script for more than one divs, lets call them members2 and members3. When i use the script more than once in a page only one of the divs works, help!

Philip M
02-25-2007, 08:11 PM
You cannot have two or more Javascripts with the same function or variable names, as the second (or last) overwrites the first.

You will have to go through and rename all these in some way e.g.

function createCookie2(name2,value2,days2)

TaboTabo
02-25-2007, 11:24 PM
Thanks, but can you tell me the things i need to change, i have been tryng and i
cant so this :S



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum