473,387 Members | 1,603 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.

How to hide table rows with the help of getElementsByName()?

AR
Hi,
How can I hide table rows? ... tried with the following example:
FireFox works... How to do the simillar in IE6?

<html>
<head>
<script language="javascript">
function hide_row() {
var v = document.getElementsByName("trBook");
v[0].style.display = 'none';
v[1].style.display = 'none';
v[2].style.display = 'none';
}
</script>
</head>
<body>
<table>
<tr name="trBook"><td>line1</td></tr>
<tr name="trBook"><td>line2</td></tr>
<tr name="trBook"><td>line3</td></tr>
</table>
<input type=button name="v" value="Hide" onclick="hide_row()">
</body>
</html>

Thanks in advance

AR

Jul 23 '05 #1
3 16884


AR wrote:

var v = document.getElementsByName("trBook"); <tr name="trBook"><td>line1</td></tr>
<tr name="trBook"><td>line2</td></tr>
<tr name="trBook"><td>line3</td></tr>


The name attribute is not defined for <tr> elements so you are relying
on browser quirks to give you a result with getElementsByName. Consider
accessing the table and then its rows collection if you want to script
the <tr> elements in that table.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
AR wrote:
Hi,
How can I hide table rows? ... tried with the following example:
FireFox works... How to do the simillar in IE6?

<html>
<head>
<script language="javascript">
function hide_row() {
var v = document.getElementsByName("trBook");
v[0].style.display = 'none';
v[1].style.display = 'none';
v[2].style.display = 'none';
}
</script>
</head>
<body>
<table>
<tr name="trBook"><td>line1</td></tr>
<tr name="trBook"><td>line2</td></tr>
<tr name="trBook"><td>line3</td></tr>
</table>
<input type=button name="v" value="Hide" onclick="hide_row()">
</body>
</html>

Thanks in advance

AR


document.getElementsByName() is only implemented for input and img
elements in iewin/Opera. Use a TBODY with an id:

function hide_row()
{
var el;
if (document.getElementById
&& (el = document.getElementById('trBook')))
{
el.style.display = 'none';
}
}
..........
<table>
<tbody id="trBook">
<tr><td>line1</td></*tr>
<tr><td>line2</td></*tr>
<tr><td>line3</td></*tr>
</tbody>
</table>

If you need to do this with individual rows, you can use a naming
convention of some sort, or selectively apply the
..getElementsByTagName() method.

Jul 23 '05 #3
On Thu, 30 Jun 2005 09:24:22 -0700, AR <ar********@yahoo.com> wrote:
Yes, as Martin said, use the rows[] collection for the table element:

document.getElementById('YOURTABLEIDHERE').rows[3].style.display='none';
//sets the
style.display for it to 'none';

Another way will be using associative IDs for the relevant elements and
iterate
through them.

Danny

--Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Harry | last post by:
I want to provide a drill down facility for the users - the plan is to intially display a table with summary rows containing results of previous selected search criteria. In each summary row you...
2
by: KathyB | last post by:
Hi, I'm trying to get the following script to work, but I'm getting an error saying "rowID is undefined". function showhide(rowId) { var showRow = "Edit_" + rowID var hideRow = "View_" + rowID...
2
by: Mark | last post by:
Hi, I need to be able to have five different links and when when someone clicks to show row 2, row 1 automatically hides. Right now all i can figure out is a link that will show but then you...
5
by: Marek Mänd | last post by:
Please explain to a experienced fool like me, how to hide table rows correctly at this case. http://marekmand.kuubik.ee/iebug_canthide_table_rows_properly.htm Click on the header "label" and see...
9
by: Wang, Jay | last post by:
I try to group several rows in a table into a div and show/hide them by click on a button somewhere with a javascript link. When clicked, the link will toggle the style of the div section's style...
1
by: RA | last post by:
Hi I want to have a FAQ so that when the user clicks the question the answer will be shown below the questions. How do I do it? I use c# with asp.net. Thanks
1
by: shankwheat | last post by:
I'm creating a dynamic table with asp and I would like to add a "Show All" and "Collapse All" feature to show/hide certain rows within the table. This code works well for showing/hiding one row at...
11
by: jimstruckster | last post by:
I have a table with 10 rows, I want all rows except for the first to be hidden when the page first opens up. If the user puts a value in a text box in the first row then I want the second row to...
1
by: jbreaker | last post by:
Hi - I have a table with about 30 rows, which contain a checkbox and a bit of text each. What I'm trying to find a way to do is to have 2 buttons at the bottom of the page - HIDE & SHOW. When the...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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,...
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...

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.