This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Make rows not appear when certain row value appears

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

The issue being is how not to load a row when a certain value appears in that column's row.
For example, there are 2 rows displayed in a html table:
Row1Column1 Row1Column2
Row2Column1 Row2Column2
When any value in column 2 equals Row2Column2, I do not want to display the row. So in this case only values in row 1 are displayed.
In the following for example I do not want to display row 2 that has the value Row2Column6.

Thanks for your help in advance!

The code is as follows
 
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 really should learn basic CSS and stop using depreciated tags.


should just be


In reality your table should look like this


and the CSS could look something like this



Now that your table markup is clean.

You can loop through the rows and cells


Eric
 
Kevin Wong
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric

Thanks for your advice.
I was wondering where exactly to call the javascript to compare values and delete rows?

I was thinking I would call it in the <body onload="callJavascriptFunction"> after the table had loaded
but there is a null reference error when referring to the table, most probably the table reference does not exist anymore.
For example I used the following code with the <body onload="loaded(inbox)">

 
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
Please use code tags when you post
 
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
well this appears to be wrong


says it is looking for a variable called inbox. I am guessing you want a string there.

When you loop through the table and delete a row, you need to do it in reverse order, start at the end and go backwards.

The way you are doing it, you delete a row and than all of the indexes of the future rows move down one.

So if you had A,B,C,C,C,D,E,F

and you were deleting C

You would have expected

A,B,D,E,F

but instead you get

A,B,C,D,E,F

Eric
 
Kevin Wong
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric

Thanks for your help!
I have fixed the logic with the loop as you have mentioned.
But I am still wondering how to delete the row(s) when the value is found in the row.
When exactly would this Javascript be called to compare the value and delete the row,
could you provide a code snippet of where this Javascript could be called to compare values and delete the row?
Is the <body onload="somejavascript"> a good place to place this because I am getting table referencing errors?
 
Kevin Wong
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric

Thanks for your help.
Problem solved and yes the problem was the I should be using a string in
body onload="loaded()"

 
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
Now your issue is you want the text and not the html markup.

The solution is to not use innerHTML which gives you all of that. You need to use textContent or innerText



Eric
 
Kevin Wong
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric

Thank you for your help so far.

I realised that the row is not being deleted from the browser when the value is being found.
That is using the onload event is being run after the page is browser page loaded and so the row cannot be deleted from the browser.
Is my understanding correct, if it is, is there a way to delete the row from the table before or during it is been generated for display.
 
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 would have to do it on the server. I am not sure why you would not do this there in the first place since it is a better user experience.

You could also add the code right after the table without onload. This would do it before the page fully renders.

Eric
 
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
If you want it to be gone from view source, that is impossible to do with JavaScript.

Eric
 
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic