Bytes Expert Newtork: Connect with experts in IT / Business | Expert Topics



Search


Go Back   Programmers Resource > Programming Forums > JavaScript
User Name
Password


Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 05-08-2009, 05:30 PM
arkleyjoe arkleyjoe is offline
Registered User
 
Join Date: Aug 2007
Posts: 3
workis perfectly in FF,CH,SF,OP but not IE

I am using this script to move some layers in and out of view. I works like a dream in every browser i can find apart from ie.

can anyone shed and light.

JS below.

I am getting an object required error in i.e.

I think it is someting to do with . . . if (parseInt(document.getElementById(layerin).style.l eft) >= inpos)

var pos = "";

var styleSwitch = " ";
var layerin = " ";
var layerout = " ";
var countin = 0;
var plan = " ";
var i = " ";
var l = " ";
var arr = " ";
var c=0;
var t;
var newpos = " ";
var currposs = " ";
var findMeText = " ";
var layerRef="document.getElementById";
var speed = 38;
var delay = 1;
var outpos = 760;
var inpos = 380;
var pause = 2000;
var rotatedivs = "";



function find_div_class() {
var divCollection = document.getElementsByName("rotate");
rotatedivs = new Array();
for (var i=0; i<divCollection.length; i++) {
if(divCollection[i].getAttribute("name") == "rotate") {

findMeText = divCollection[i].getAttribute("id");
rotatedivs[i] = findMeText;

}

}

}





function initlayers()
{
arr=rotatedivs;

l = arr.length;
for (i=0; i <= l-1; i++)
{
eval(layerRef+'(["'+arr[i]+'"]).style.left = "798px"');
eval(layerRef+'(["'+arr[i]+'"]).style.visibility="hidden"');

}
}





function pauseit(div) {
moveinout(div);
if (t !== null) {
clearTimeout(t);
t = null;
}
}


function playit() {
if (t === null) {
t = setTimeout('rotatelayers()', 1000);
}
}





function movein()
{

if (parseInt(document.getElementById(layerin).style.l eft) >= inpos)

{

currposs = parseInt(document.getElementById(layerin).style.le ft);

newpos = currposs - speed;
document.getElementById(layerin).style.visibility ="visible";
document.getElementById(layerin).style.left = newpos +"px";
setTimeout('movein()',delay);
}
else
{

countin = 0;
}

}


function moveout()
{

if (parseInt(document.getElementById(layerout).style. left) <= outpos)
{
currposs = parseInt(document.getElementById(layerout).style.l eft);
newpos = currposs + speed;
document.getElementById(layerout).style.left = newpos +"px";
setTimeout('moveout()', delay );
}
else
{
document.getElementById(layerout).style.visibility ="hidden";
movein();
}

}


function moveinout(div)
{

if (countin === 0)
{
countin = 1;
layerout = layerin;
layerin = div;

if (layerout != " ")
{

moveout();
}
else
{

movein();
}
}
}


function rotatelayers()

{

arr = new Array();
arr=rotatedivs;
l = arr.length;



moveinout(arr[c]);

c=c+1;

if(c == l)
{
c=0;

}

t=setTimeout("rotatelayers()",pause);

}


function StartCCTVportfolio()
{

find_div_class();
//showlayers("logos");
initlayers();

rotatelayers();

}
Reply With Quote
  #2  
Old 05-08-2009, 11:03 PM
Nook Schreier's Avatar
Nook Schreier Nook Schreier is offline
Mooderater
 
Join Date: Feb 2006
Location: Ohio
Posts: 579
It's hard to tell exactly what the problem is without more info to trace everything. But that error can come up if document.getElementById() looks for a nonexistent ID, so it might be worth your while to modify your code to make sure that it exists first. If it doesn't exist, getElementById will return NULL, which of course would have no style property. Something like:
Code:
function moveout() { if (document.getElementById(layerout) != null) { if (parseInt(document.getElementById(layerout).style. left) <= outpos) [...]
That wouldn't explain why it doesn't occur in other browsers, but it's worth doing. At the very least it might help a little in track down the actual problem.
__________________
www.NookSchreier.Net
Reply With Quote
  #3  
Old 05-11-2009, 05:32 AM
arkleyjoe arkleyjoe is offline
Registered User
 
Join Date: Aug 2007
Posts: 3
[solved]

It turns out that in the HTML i was using both the name and id attribute, which IE treats as one while others handle sperately.

In the end i sound a script to perform a getelementbyclass function. I modifiled my code and used that and all is now well.

Thanks for coming back to me.

Regards

Joe
Reply With Quote
  #4  
Old 05-11-2009, 09:44 AM
Nook Schreier's Avatar
Nook Schreier Nook Schreier is offline
Mooderater
 
Join Date: Feb 2006
Location: Ohio
Posts: 579
That's interesting. With my usual sloppy coding (on my own projects), I'm surprised I haven't encountered that.
__________________
www.NookSchreier.Net
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump



All times are GMT -5. The time now is 07:54 AM.



Powered by: vBulletin Version 3.0.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
All content Copyright ©1999 - 2010, Programmers Resource, unless otherwise noted.