By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,654 Members | 1,582 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.

Hiding function works on IE, but it doesn't on Moziila

P: n/a
Hi, i'm wondering why this hiding and showing function works on IE (6) but
it doesn't work in Mozilla Firebird (0.7)

function fnc_show(num){

for(i=1;i<7;i++){
eval("t_" + i + ".style.display = \"none\"");
}
eval("t_" + num + ".style.display = \"inline\"");

}

t_1, t_2 ...t_7 are the ids for TR elements in a table, i.e. with
fnc_show(3), it will show only t_3. This works without a problem on IE, but
it seems to do nothing in Mozilla, i only get an error telling that t_1 is
not defined.

I'm wondering too, if there is a better way to do it, cause i read that eval
function is inefficient .

Any ideas?

Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"atomo" <at***@none.cl> wrote in message
news:bp**********@news1.nivel5.cl...
Hi, i'm wondering why this hiding and showing function works on IE (6) but
it doesn't work in Mozilla Firebird (0.7)

function fnc_show(num){

for(i=1;i<7;i++){
eval("t_" + i + ".style.display = \"none\"");
Use: document.getElementById("t_"+i).display="none";
}
eval("t_" + num + ".style.display = \"inline\"");


Use: document.getElementById("t_"+i).display="";

Vjekoslav
Jul 20 '05 #2

P: n/a
"atomo" <at***@none.cl> writes:
Hi, i'm wondering why this hiding and showing function works on IE (6) but
it doesn't work in Mozilla Firebird (0.7)
I wonder why it works in IE. But, alas, it does, and we have to live
with it.
function fnc_show(num){

for(i=1;i<7;i++){
eval("t_" + i + ".style.display = \"none\"");
Never use eval to find the value of a variable or property. Never.
Almost never use eval at all. It is slow and inefficient, and it
hides errors far too well.

You have an element with the id "t_1". You then assume that that
element is available as a global variable of the same name. That
is true for IE, but luckily not for many other browsers (no need
to pollute the global namespace like that!).

To get an element from its id, use
document.getElementById("t_"+i).style.display = "none";
}
eval("t_" + num + ".style.display = \"inline\"");
and

document.getElementById("t_"+num).style.display = "inline";
}

t_1, t_2 ...t_7 are the ids for TR elements in a table, i.e. with
fnc_show(3), it will show only t_3. This works without a problem on IE, but
it seems to do nothing in Mozilla, i only get an error telling that t_1 is
not defined.
That is because there is no global variable called "t_1".
I'm wondering too, if there is a better way to do it, cause i read that eval
function is inefficient .


Oh, yes! Very inefficient! And there is (almost) always a better way.
What that better way is, depends on what you try to do.
The FAQ says: <URL:http://jibbering.com/faq/#FAQ4_40>

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3

P: n/a
Thanks!!!!
it worked fine.

"Lasse Reichstein Nielsen" <lr*@hotpop.com> escribió en el mensaje
news:ll**********@hotpop.com...
"atomo" <at***@none.cl> writes:
Hi, i'm wondering why this hiding and showing function works on IE (6) but it doesn't work in Mozilla Firebird (0.7)
I wonder why it works in IE. But, alas, it does, and we have to live
with it.
function fnc_show(num){

for(i=1;i<7;i++){
eval("t_" + i + ".style.display = \"none\"");


Never use eval to find the value of a variable or property. Never.
Almost never use eval at all. It is slow and inefficient, and it
hides errors far too well.

You have an element with the id "t_1". You then assume that that
element is available as a global variable of the same name. That
is true for IE, but luckily not for many other browsers (no need
to pollute the global namespace like that!).

To get an element from its id, use
document.getElementById("t_"+i).style.display = "none";
}
eval("t_" + num + ".style.display = \"inline\"");


and

document.getElementById("t_"+num).style.display = "inline";
}

t_1, t_2 ...t_7 are the ids for TR elements in a table, i.e. with
fnc_show(3), it will show only t_3. This works without a problem on IE, but it seems to do nothing in Mozilla, i only get an error telling that t_1 is not defined.


That is because there is no global variable called "t_1".
I'm wondering too, if there is a better way to do it, cause i read that eval function is inefficient .


Oh, yes! Very inefficient! And there is (almost) always a better way.
What that better way is, depends on what you try to do.
The FAQ says: <URL:http://jibbering.com/faq/#FAQ4_40>

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors:

<URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html> 'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.