aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Hiding Table Rows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Hiding Table Rows" Watch "Hiding Table Rows" New topic
Author

Hiding Table Rows

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1475
    
    1
I know this probably is crazy but here goes anyway.

I am populating a table using JSTL. I am giving the same ID to several rows. I have put a onclick on the row also so I can verify the row ID value. Now when I fire the following it only hides the first row but I want to hide all the rows with that ID:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61588
    
  67

Originally posted by Steve Dyke:
I am giving the same ID to several rows.[/CODE]

Then your markup is invalid. It will not work in any way that you can count on. Try using class names instead of ids to identify the elements to be operated upon.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Just to clarify what Bear is saying: IDs are singular, just like your bank account number, drivers license, government id number, etc. You can not have more than one element on the page with the same id.

Eric
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1475
    
    1
Originally posted by Bear Bibeault:

Try using class names instead of ids to identify the elements to be operated upon.


Can you explain how this is done?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You build a function or use a built in method that looks up the classnames of the elements on the page.

You might want to start with a google search for getElementsByClassName

[I think you used JQuery?]

Eric
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1475
    
    1
Okay. But how will this help me identify a set of table rows then hide those table rows only? Don't all table rows belong to the same class?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You give them another class, just like you were giving them an id previously. [You can have more than one class on an element.]

Eric
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1475
    
    1
I have found and added this JS to my code but I get an error that getElementsByClassName().style is null or not an object.

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You need to learn how to debug.

Look at the code you are using.

It is returning the contents of the variable retnode;

retnode is declared as var retnode = [];

[] is shorthand notation for new Array();

So that means you have an array, so you need to loop through the array and set the styles of each element.

Eric
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1475
    
    1
Sorry to keep being a pest but I get error Object Required with this code.

Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

if still doesn't know which line of code is giving you the error then try fire bug.. to debug your code..

hope it helps.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1475
    
    1
I do know the line generating the error

document.getElementById(t1[x]).style.display = "none";
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
That code returns the object of the element. There is no need to use getElementById with it.



Eric
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1475
    
    1
Thanks.
[ October 01, 2008: Message edited by: Steve Dyke ]
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Hi Eric,

There is no need to use getElementById with it.


is this because that this is the underline method of document Object, which is used to access all elements in a page instead of access from the array?

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hiding Table Rows