By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,654 Members | 1,419 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,654 IT Pros & Developers. It's quick & easy.

Problems setting style attrabutes of multiple layers

P: n/a
I have a couple of layers that are hidden.

When an image is moused over, I want to show the appropriate layer,
then hide it on mouseOut.

The problem is, I get an error telling me "document.all[...].style is
not an object" for whatever layer I have created first. It seems as
though when the second layer is created, it overwrites the first one
....

This has been driving me NUTS! Any suggestions?

Heres my code:

javascript :

function helpWin(meth,obj){
if(meth=="show"){
document.all[obj].style.visibility = 'visible';
}else if(meth=="hide"){
document.all[obj].style.visibility = 'hidden';
}
}

HTML :

<!-- -->
<div id="bcc" style="position:absolute; border: 1px solid balck;
left:420px; top:0px; width:300px; height:50px; z-index:1;
background-color: #FFFFFF; layer-background-color: #FFFFFF;
visibility: hidden;">
<span class="mainTitle">Some Text</span></div>
<!-- -->
<div id="toc" style="position:absolute; border: 1px solid balck;
left:420px; top:0px; width:300px; height:50px; z-index:2;
background-color: #FFFFFF; layer-background-color: #FFFFFF;
visibility: hidden;">
<span class="mainTitle">Some Text</span></div>
<!-- -->

<img src="q.gif" width="10" height="10"
onMouseOver="helpWin('show','bbc');"
onMouseOut="helpWin('hide','bbc');">

<img src="q.gif" width="10" height="10"
onMouseOver="helpWin('show','toc');"
onMouseOut="helpWin('hide','toc');">
Jul 23 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Hi,

In article <c7**************************@posting.google.com >, Eclectic wrote:
solid balck;
it's definitely dangerous to use 'solid balck;'. I'd recommend a spell checker. Dreamweaver does a good job
for that kind of things.

For the other problem of yours,
The problem is, I get an error telling me "document.all[...].style is
not an object" for whatever layer I have created first. It seems as
though when the second layer is created, it overwrites the first one


Use this script, I don't remember where I got it from, and lost the copyright message, thanks to the author
anyway:

--------
function toggleVisibility(id, NNtype, IEtype, W3Ctype) {
if (document.getElementById) {
eval("document.getElementById(id).style.visibility = \"" + W3Ctype + "\"");
} else {
if (document.layers) {
document.layers[id].visibility = NNtype;
} else {
if (document.all) {
eval("document.all." + id + ".style.visibility = \"" + IEtype + "\"");
}
}
}
------------------

you use it like:

onMouseOut="toggleVisibility('bcc','hidden','hidde n','hidden');
onMouseOver="toggleVisibility('toc','show','visibl e','visible');

you can use it for any number of objects, for any kind of event. It's very convenient and works with (AFAIK)
every browser.

Ranbir
Jul 23 '05 #2

P: n/a
Ranbir Kaur wrote:
<snip>
if (document.getElementById) {
eval("document.getElementById(id).style.visibility = \"" +
W3Ctype + "\"");

<snip>
This has got be the most futile use of - eval - posted in a long time:-

document.getElementById(id).style.visibility = W3Ctype;

Richard.
Jul 23 '05 #3

P: n/a
Richard Cornford wrote:
Ranbir Kaur wrote:
<snip>
if (document.getElementById) {
eval("document.getElementById(id).style.visibility = \"" +
W3Ctype + "\"");

<snip>
This has got be the most futile use of - eval - posted in a long time:-

document.getElementById(id).style.visibility = W3Ctype;


Not this way, see <http://www.pointedears.de/scripts/test/whatami>.
Instead write:

var t;
if ((t = typeof document.getElementById) == "function"
|| (t == "object" && document.getElementById))
{
var o = document.getElementById(id), s;
if (o
&& typeof o.style != "undefined"
&& typeof o.style.visibility != "undefined")
{
o.style.visibility = W3Ctype;
}
}
PointedEars
--
Life is like a french fry. It gets cold, it gets soggy, and it gets limp if
you let it lying around too long.
Jul 23 '05 #4

P: n/a
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
Ranbir Kaur wrote:
<snip>
if (document.getElementById) {
eval("document.getElementById(id).style.visibility = \"" +
W3Ctype + "\"");

<snip>
This has got be the most futile use of - eval - posted
in a long time:-

document.getElementById(id).style.visibility = W3Ctype;


Not this way, see <http://www.pointedears.de/scripts/test/whatami>.
Instead write:

<snip>

This has nothing to do with the futility of the - eval - formulation
used. If you want to talk about the code design it would make most sense
to post a response to individual who designed it, not me.

Richard.
Jul 23 '05 #5

P: n/a
Richard Cornford wrote:
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
Ranbir Kaur wrote:
<snip>
if (document.getElementById) {
eval("document.getElementById(id).style.visibility = \"" +
W3Ctype + "\"");
<snip>
This has got be the most futile use of - eval - posted
in a long time:-

document.getElementById(id).style.visibility = W3Ctype;


Not this way, see <http://www.pointedears.de/scripts/test/whatami>.
Instead write:

<snip>

This has nothing to do with the futility of the - eval - formulation
used. If you want to talk about the code design it would make most sense
to post a response to individual who designed it, not me.


I commented on your inappropriate correction.
PointedEars
--
PROZAC: Sometimes you feel like a nut, sometimes you don't.
Jul 23 '05 #6

P: n/a
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
Ranbir Kaur wrote:
<snip>
> if (document.getElementById) {
> eval("document.getElementById(id).style.visibility = \"" +
> W3Ctype + "\"");
<snip>
This has got be the most futile use of - eval - posted
in a long time:-

document.getElementById(id).style.visibility = W3Ctype;

Not this way, see http://www.pointedears.de/scripts/test/whatami
Instead write:

<snip>

This has nothing to do with the futility of the - eval -
formulation used. If you want to talk about the code design
it would make most sense to post a response to individual who
designed it, not me.


I commented on your inappropriate correction.


Are you proposing that I did not post the code for the equivalent
operations without the eval?

In any event, my post was not a correction it was an observation of
manifest futility. And frankly, referring me to your pathetic page on
feature detection, or posting your clunky and pedestrian feature
detection example, looks like trying to teach your grandmother to suck
eggs.

Richard.
Jul 23 '05 #7

P: n/a
Richard Cornford wrote:
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
> Ranbir Kaur wrote:
> <snip>
>> if (document.getElementById) {
>> eval("document.getElementById(id).style.visibility = \"" +
>> W3Ctype + "\"");
> <snip>
> This has got be the most futile use of - eval - posted
> in a long time:-
>
> document.getElementById(id).style.visibility = W3Ctype;

Not this way, see http://www.pointedears.de/scripts/test/whatami
Instead write:
<snip>

This has nothing to do with the futility of the - eval -
formulation used. If you want to talk about the code design
it would make most sense to post a response to individual who
designed it, not me.


I commented on your inappropriate correction.


Are you proposing that I did not post the code for the equivalent
operations without the eval?


I am proposing that your correction is presenting a still
inappropriate approach, although it is better than using
eval(...). Don't you understand "Not this way"?
PointedEars
Jul 23 '05 #8

P: n/a
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
Thomas 'PointedEars' Lahn wrote: <snip>
I commented on your inappropriate correction.


Are you proposing that I did not post the code for the
equivalent operations without the eval?


I am proposing that your correction is presenting a still
inappropriate approach, although it is better than using
eval(...). Don't you understand "Not this way"?


And once again you have cut the part of my post where I stated that my
first post to this thread was an observation not a correction, and then
replied as if that statement had not been made.

Richard.
Jul 23 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.