PDA

View Full Version : Clashing Code



Tabo
04-22-2007, 03:47 PM
Please read and don't be put off by the length, I'm sure the problem is quite easy to fix.

Hey, I have clashing code and i am in need with help. It is a lot to ask but i have been trying myself for a while and i have got no where. I am sure that the fault is with onload and onunload.

What are the codes?
One of them sets a cookie to remember what content to hide/show
the other code is part of a chain of codes which moves a box accross the page

So here is the two peices of clashing code, if you want to take a look at the whole page just ask but im sure the problem is within parts shown.

Code 1


<script type="text/javascript">
<!--
function WidgetRememberCreate(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 WidgetRememberRead(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 WidgetRememberDelete(name) {
WidgetRememberCreate(name,"",-1);
}

function hidewidget(id) {
toggleBox1(id,'none');
WidgetRememberCreate(id,'none');
}

function showwidget(id) {
toggleBox1(id,'block');
WidgetRememberCreate(id,'block');
}

function toggleBox1(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;
}
}

if(document.getElementsByTagName)
window.onload = function nnn() {
var divs=document.getElementsByTagName('div')
for (var i_tem = 0; i_tem < divs.length; i_tem++)
if(divs[i_tem].id!='' && WidgetRememberRead(divs[i_tem].id))
toggleBox1(divs[i_tem].id,WidgetRememberRead(divs[i_tem].id));
}

// -->
</script>


snapshot of Code 2.


<script type='text/javascript'>

var fen = new Array(), fen_count = 4; //check no of fens

window.onload = function()
{
for (var i = 1; i <= fen_count; ++i) {
fen[i] = new xfen('fen'+i, i*100, i*100, 'fenBar'+i, 'fenResBtn'+i, 'fenMaxBtn'+i);
}
}
window.onunload = function()
{
for (var i = 1; i <= fen_count; ++i) {
fen[i].onunload();
}
}
</script>


I know both of the codes are right because they both work on seporate pages.

Twey
04-22-2007, 03:53 PM
Onload conflict:
window.onload = function nnn() {
var divs=document.getElementsByTagName('div')
for (var i_tem = 0; i_tem < divs.length; i_tem++)
if(divs[i_tem].id!='' && WidgetRememberRead(divs[i_tem].id))
toggleBox1(divs[i_tem].id,WidgetRememberRead(divs[i_tem].id));
}
window.onload = function()
{
for (var i = 1; i <= fen_count; ++i) {
fen[i] = new xfen('fen'+i, i*100, i*100, 'fenBar'+i, 'fenResBtn'+i, 'fenMaxBtn'+i);
}
}Remove these two and combine them into:
window.onload = function()
{
var divs=document.getElementsByTagName('div')
for (var i_tem = 0; i_tem < divs.length; i_tem++)
if(divs[i_tem].id!='' && WidgetRememberRead(divs[i_tem].id))
toggleBox1(divs[i_tem].id,WidgetRememberRead(divs[i_tem].id));

for (var i = 1; i <= fen_count; ++i)
fen[i] = new xfen('fen'+i, i*100, i*100, 'fenBar'+i, 'fenResBtn'+i, 'fenMaxBtn'+i);
}

Tabo
04-22-2007, 04:03 PM
Thank you so muych. I would give you rep but you cant on this forum

Thanks :)