Connecting Tech Pros Worldwide Forums | Help | Site Map

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

atomo
Guest
 
Posts: n/a
#1: Jul 20 '05
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?




Vjekoslav Begovic
Guest
 
Posts: n/a
#2: Jul 20 '05

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


"atomo" <atomo@none.cl> wrote in message
news:bpoqif$pad$1@news1.nivel5.cl...[color=blue]
> 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\"");[/color]

Use: document.getElementById("t_"+i).display="none";
[color=blue]
> }
> eval("t_" + num + ".style.display = \"inline\"");
>[/color]

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

Vjekoslav


Lasse Reichstein Nielsen
Guest
 
Posts: n/a
#3: Jul 20 '05

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


"atomo" <atomo@none.cl> writes:
[color=blue]
> Hi, i'm wondering why this hiding and showing function works on IE (6) but
> it doesn't work in Mozilla Firebird (0.7)[/color]

I wonder why it works in IE. But, alas, it does, and we have to live
with it.
[color=blue]
> function fnc_show(num){
>
> for(i=1;i<7;i++){
> eval("t_" + i + ".style.display = \"none\"");[/color]

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";
[color=blue]
> }
> eval("t_" + num + ".style.display = \"inline\"");[/color]

and

document.getElementById("t_"+num).style.display = "inline";
[color=blue]
> }
>
> 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.[/color]

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

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 - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
atomo
Guest
 
Posts: n/a
#4: Jul 20 '05

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


Thanks!!!!
it worked fine.

"Lasse Reichstein Nielsen" <lrn@hotpop.com> escribió en el mensaje
news:llq8ynjz.fsf@hotpop.com...[color=blue]
> "atomo" <atomo@none.cl> writes:
>[color=green]
> > Hi, i'm wondering why this hiding and showing function works on IE (6)[/color][/color]
but[color=blue][color=green]
> > it doesn't work in Mozilla Firebird (0.7)[/color]
>
> I wonder why it works in IE. But, alas, it does, and we have to live
> with it.
>[color=green]
> > function fnc_show(num){
> >
> > for(i=1;i<7;i++){
> > eval("t_" + i + ".style.display = \"none\"");[/color]
>
> 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";
>[color=green]
> > }
> > eval("t_" + num + ".style.display = \"inline\"");[/color]
>
> and
>
> document.getElementById("t_"+num).style.display = "inline";
>[color=green]
> > }
> >
> > 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,[/color][/color]
but[color=blue][color=green]
> > it seems to do nothing in Mozilla, i only get an error telling that t_1[/color][/color]
is[color=blue][color=green]
> > not defined.[/color]
>
> That is because there is no global variable called "t_1".
>[color=green]
> > I'm wondering too, if there is a better way to do it, cause i read that[/color][/color]
eval[color=blue][color=green]
> > function is inefficient .[/color]
>
> 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 - lrn@hotpop.com
> DHTML Death Colors:[/color]
<URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>[color=blue]
> 'Faith without judgement merely degrades the spirit divine.'[/color]


Closed Thread


Similar JavaScript / Ajax / DHTML bytes