• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Hiding Table Rows

 
Ranch Hand
Posts: 2282
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2282
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2282
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2282
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2282
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry to keep being a pest but I get error Object Required with this code.

 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Steve Dyke
Ranch Hand
Posts: 2282
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do know the line generating the error

document.getElementById(t1[x]).style.display = "none";
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That code returns the object of the element. There is no need to use getElementById with it.



Eric
 
Steve Dyke
Ranch Hand
Posts: 2282
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
[ October 01, 2008: Message edited by: Steve Dyke ]
 
Muhammad Saifuddin
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic