aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Make rows not appear when certain row value appears Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Make rows not appear when certain row value appears " Watch "Make rows not appear when certain row value appears " New topic
Author

Make rows not appear when certain row value appears

Kevin Wong
Greenhorn

Joined: Mar 28, 2009
Posts: 12
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
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Mar 28, 2009
Posts: 12
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
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Please use code tags when you post
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Mar 28, 2009
Posts: 12
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

Joined: Mar 28, 2009
Posts: 12
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
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Mar 28, 2009
Posts: 12
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
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
If you want it to be gone from view source, that is impossible to do with JavaScript.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Make rows not appear when certain row value appears