Click to See Complete Forum and Search --> : getting a document.all[...].filters is null or not an object error


mystx
10-18-2003, 07:18 PM
Hi!

This is the situation! I'm trying to make a script that would fade in/out a DIV box.

function setOpacity(objectId,objectOpacity) {

if (document.all){
document.all(objectId).filters.alpha.opacity = objectOpacity
} else if (!document.all && document.getElementById) {
document.getElementById(objectId).style.MozOpacity = objectOpacity/100
}
}

function fadeDiv(id) {
divOpacity = divOpacity - oAmount
if (divOpacity > 0) {
setOpacity(id,divOpacity)
setTimeout("fadeDiv()",1)
}
}

and in the body is:
<div id="bigDiv" class="div1"></div>

<button class="theButton" onclick="fadeDiv('bigDiv')">Test</button>



Now, the goal is, when I click the "Test" button, function fadeDiv() is called and the DIV id is passed to it.
In the fadeDiv() function you can see that there is a call to setOpacity() function. Now here comes the problem: that variable "id" in setOpacity(id,divOpacity) is supposed to be passed to function setOpacity() and that variable is really passed but I allways get error document.all[...].filters is null or not an object.I suspect there's a problem with passing the variable to setOpacity() function.

I'm rather new to this so please help me out if you can. Thanx!

gil davis
10-19-2003, 09:19 AM
Try hard-coding the DIV id just to see if the syntax is right:
document.all["bigDiv"].filters.alpha.opacity = objectOpacity;
I suspect that the filter has to exist in the style of the DIV before you can access it, but I could be wrong.

Here is a link on filters that might be helpful:
http://msdn.microsoft.com/workshop/author/filter/filters.asp

Here is a demo page that I wrote that uses revealTrans filters:
http://gil.davis.home.att.net/wipe.htm

mystx
10-19-2003, 12:53 PM
This thing works:

document.all["bigDiv"].filters.alpha.opacity = objectOpacity;
or if instead of

setOpacity(id,divOpacity)

I put

setOpacity("bigDiv",divOpacity)

it also works. I'm just wondering why it doesn't work when I try to pass the DIV id like a variable. This is the DIV :

.div1 {position:absolute;top:5px;left:455px;width:232px;height:143px;z-index:3;background-color:#000000;filter:alpha(opacity=10);-moz-opacity:1}

so you can see the filter exists (sorry I didn't post it earlier)

gil davis
10-19-2003, 04:01 PM
Maybe you are being bitten by your choice of a reserved word for a variable name.

Use an alert to show what is being passed to the setOpacity function.

mystx
10-19-2003, 04:44 PM
I tried to do it with alert and alert box says "bigDiv" which is correct but after the alert box i get a second alert box wich says only one word : "undefined"! I have put only one alert so now I'm confused, why 2 alert boxes pop out and what is undefined?

Do you have any clue?

gil davis
10-19-2003, 05:23 PM
You are apparently calling the routine twice.