473,387 Members | 1,374 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,387 software developers and data experts.

Works in IE but not in FF - Please Help

I have multiple rows in a table that I can toggle their visibility in IE 6 using the function below. However, this does not work in FF 2.x. I can't use getElementById() because I need to identify multiple <TR> tags in the document.

Can someone please show me how to recode this function below to work in both browsers. TIA.

function hideEmptyFields_ff()
{
var oLink = document.getElementById('hidelink')
//var oImages = document.getElementsByTagName('TR');
var oRows = document.all || document.getElementsByTagName('TR');

if (oRows.length)
{
for (var i = 0; i < oRows.length; i++)
{
var oRow = oRows[i]
if (oRow.name == 'emptyrow')
{
if (oRow.style.display == 'none')
{
oRow.style.display = '';
oLink.innerHTML = 'Hide Empty Fields'
}
else
{
oRow.style.display = 'none';
oLink.innerHTML = 'Show Empty Fields'
}
}
}
}
}
Mar 29 '07 #1
3 1572
acoder
16,027 Expert Mod 8TB
What's the default style setting for the rows?
Mar 29 '07 #2
Not sure what you mean by default setting for the rows. I can tell you that the rows in the table I want to hide are given the following attribute:

name='hiderow'

These are rows that represent empty fields from my data source so I am giving the user an option to hide these empty rows.

Most examples providing an alternative to IE's document.all suggest using getElementById() but this only works for single object in the DOM. Since I want to find multiple rows, I used the name attribute instead where I can have multiple objects with the same name. So I needed to use getElementsByTagName() (notice the plurality of elements in the name) to get a collection of all the rows with this attribute.

After researching the getElementsByTagName(), I was able to construct an alternate function that appears to work in both IE 6 and FF 2.x and is shown below. It appears that assigning an single a single object in the collection to a new variable does not work in FF although this appears like a standard OO contruct. Or maybe I just missed something simple.

var oRow = oRows(iImg);

Here it function that works in both IE 6 and FF 2.x:

function hideEmptyFields_ff()
{
var oLink = document.getElementById('hidelink')
//var oImages = document.getElementsByTagName('TR');
var oRows = document.all || document.getElementsByTagName('TR');

for (var i = 0; i < oRows.length; i++)
{
n = oRows[i].getAttribute("name");
if (n == 'emptyrow')
{
if (oRows[i].style.display == 'none')
{
oRows[i].style.display = '';
oLink.innerHTML = 'Hide Empty Fields'
}
else
{
oRows[i].style.display = 'none';
oLink.innerHTML = 'Show Empty Fields'

}
}
}
}

Does anyone see a problem with this code?

I did see an example where the table is and ID and getElementById() is used to first get a reference to the table and then the table reference is used to get all ('TR') tags. I guess this might improve speed since the initial collection is limited to the table to locate the rows. Perhaps I will try this and post again if the difference it worth noting. TIA.


Finally, an interesting observation is that I can call this function from the <Body> tag's onload event so that the "named" rows are actually hidden before the page first displays. IE 6 instantly displays the page with the rows already hidden while FF displays the page with rows as visible and then after a fraction of second, the rows are hidden which is not desirable. FF apparently displays the page and then runs the function to hide the rows after the fact. I am trying to like FF but in this case, IE 6 appears to handle this in a superior way. Is there a way to have FF not display the page until the rows are hidden?
Mar 29 '07 #3
iam_clint
1,208 Expert 1GB
var oRows = document.getElementsByTagName('TR');
Mar 29 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: SÁRINGER Zoltán | last post by:
Hello! I have an ASP page using Jet 4.0 oldeb provider for mdb. (ADO 2.8). I use the _same_ code in ASP from my well working VB application. The problem is: when I do the same "SELECT * FROM...
5
by: gabbott | last post by:
I've designed a very simple VB.NET project that uses the .NET framework functionality to access registry keys. At the moment it pulls values from a few keys and puts them into a listbox. The...
2
by: James Zhuo | last post by:
Accessing Items in a Collection works with the as suggested by Kevin and Chris (thx) But when i tried to use the same technic with databinding within the aspx file, it doesn't seem to work. This...
6
by: goober | last post by:
Ladies & Gentlemen: I have built a form that client-side validates and posts data to a CRM beautifully in Internet Explorer (IE) 6. The problem comes in FireFox (FF) 1.5 when everything works...
10
by: Smurff | last post by:
Hi, This code works fine on win and linux but not on hpux. All is compiled with gcc. Can anyone help please? /*****************************************************************************/ /*...
1
by: Ethan Strauss | last post by:
Hi, I have a C#.net Web application which calls a web service (http://eutils.ncbi.nlm.nih.gov/entrez/eutils/soap/eutils.wsdl). It has run just fine for months. Recently I started getting...
9
by: Dave | last post by:
Hi, I've been trawling the web for answer to my problem with no luck although I'm hardly alone it seems! Below is the generated source for an ASP page that posts a value called 'album' to...
8
by: John Austin | last post by:
I need to understand why if I add a control and use AddHandler to connect its click event, it will work in Page_Load, but not in a Button_Click. The idea is that the user types some data, presses...
8
by: Brett | last post by:
I wrote an ASP.NET application that queries a SQL Server database (on a different box from the web server) and displays the result in a GridView. The datasource for the GridView is a SQLDataSource....
1
by: =?Utf-8?B?amVubmlmZXI=?= | last post by:
Im sure this question has been asked but I cant seem to find an answer I understand. I have works 9 on vista. Everytime I try to open an attachment or send a document from it I get an error. I have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.