473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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

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
3 1746
"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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Lorenzo Villari | last post by:
I premise I don't know C++ well but... I wondered what is this data hiding thing... I mean, if I can look at the header (and i need it beacuse of the class), then what's hidden? Can someone give...
39
by: WindAndWaves | last post by:
Hi Gurus I have a page, which looks a bit like this: .... <body> <div ID=id1>................</DIV> <div ID=gsd>................</DIV> <div ID=ewd>................</DIV> <div...
9
by: bob | last post by:
Hi, I know there exists a good reason why the designers of c++ decided that function hiding should exist. But I don't know why. Can anybody provide a good reason/example of a case where function...
24
by: Kourosh | last post by:
I have a lot of DIV tags on an HTML page. I want to group some of them so that I can hide them all together at once if needed. What's a good way to do this? I want this to be compatible with at...
12
by: Ste | last post by:
Hi there, I've got a website with a list of Frequently Asked Questions, so there's a question and answer in a long list down the page. Can anyone recommend a simple script that would allow me...
0
by: Frank | last post by:
Hi, I have read the other post about hiding the updatepanel using the ajax lifecycle as such at the end of the aspx page: <script type="text/javascript" language =javascript> var c = new...
2
by: developer.new | last post by:
Hi I have a question regarding this concept I learned about recently: Name Hiding. Here's what I've come across: There is a base class with two functions with the same name but different...
11
by: JJ297 | last post by:
I want to hide the Pin field below in my repeater. How do I do this? <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"> <ItemTemplate> <tr> <td><font...
162
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.