javascript woes... should be easy - hiding classes with a twist

Al Neri

Diamond Member
Jan 12, 2002
5,680
1
81
I'm currently making a table of baseball data--

I'm trying to make a table that will hide multiple rows in javascript... now I put together a way to do it by class, but it is not fully doing it the way I wanted it to. I found and built some code as an attempt to get it to work - but apparently I didn't do a good job. Where indexOf is - I changed it from regex - because I want to see if the class contains the text - not if the class IS the text... however it did not seem to work.

The reason for that is, players can be multiple positions.

I'm using PHP to output the positions it's all coming from mySQL. So if the particular player is multiple positions it outputs it as such <tr class="pos-POSITION1-POSITION2-...> for example <tr class="pos-T2B-T1B-LF">...

if he is just one position it is outputted as such <tr class="pos-T1B">

Am I doing something wrong with my code - or what? Thanks so much for the help, see below for the code, I also have it running at

http://www.shopforeveryone.com/test.php

Thanks for any help!

Don R.
 

JasonCoder

Golden Member
Feb 23, 2005
1,893
1
81
Ok so you've got a string "pos-T2B-T1B-LF" which I assume signifies that the player plays 2nd base, 1st base and Left Field (talk about a utility player, Ryan Freel eat your heart out). So you want to take and see if the dude plays 1st by saying elem.className.indexOf("T1B") > -1 where elem is the TR tag right?

Seems like that should work to me. What is it doing? Just looked at your page and it looks like you've got it working?
 

PhatoseAlpha

Platinum Member
Apr 10, 2005
2,131
21
81
In the page you linked, the function getElementsByClass(searchClass,node,tag) is never actually called, and I suspect that's what you want it to be using. You call getElementsByClassName, which calls the built in getElementsByClassName function, and your custom search code never gets called.


Suggestion though: You can in fact have elements that are members of multiple classes. instead of class='position1-position2-position3' have class='position1 position2 position3'. The former puts you in a single class 'position1-position2-position3' - the later is in three seperate classes 'position1', 'position2' and 'position3' Changing any of your multiple position players to a multi-class element instantly makes it function properly.




 

DannyBoy

Diamond Member
Nov 27, 2002
8,820
2
81
www.danj.me
Originally posted by: Al Neri
I'm currently making a table of baseball data--

I'm trying to make a table that will hide multiple rows in javascript... now I put together a way to do it by class, but it is not fully doing it the way I wanted it to. I found and built some code as an attempt to get it to work - but apparently I didn't do a good job. Where indexOf is - I changed it from regex - because I want to see if the class contains the text - not if the class IS the text... however it did not seem to work.

The reason for that is, players can be multiple positions.

I'm using PHP to output the positions it's all coming from mySQL. So if the particular player is multiple positions it outputs it as such <tr class="pos-POSITION1-POSITION2-...> for example <tr class="pos-T2B-T1B-LF">...

if he is just one position it is outputted as such <tr class="pos-T1B">

Am I doing something wrong with my code - or what? Thanks so much for the help, see below for the code, I also have it running at

http://www.shopforeveryone.com/test.php

Thanks for any help!

Don R.

Why are you concatenating class names?