Link to home
Start Free TrialLog in
Avatar of Refael
RefaelFlag for United States of America

asked on

jQuery Calculate based columns text

Hello Experts,

I need to perform something simple calculation yet when I look at my coding it seems quite long so i think there should be a better way, more pro :-)

I have a 7 columns table in the following structure:

01 | YELLOW | text | text | text | FREE
02 | BLUE | text | text | text | RESERVED
03 | BROWN | text | text | text | SOLD

There are many more COLORS ....

What I need to do using jQuery is:

1). Calculate how many YELLOW, BLUE, BROWN are listed (how many from each)
2). How many from each are FREE, RESERVED+SOLD (reserved+sold should be calculated as SOLD.)

I started like this but it is going to be pretty much long and i am not sure that's the most efficient way.

var TotalYellow = $('table td:contains("YELLOW")').size(); 
var TotalBLUE = $('table td:contains("BLUE")').size();
var TotalBrown = $('table td:contains("BROWN")').size(); var TotalRED = $('table td:contains("RED")').size(); $(TotalYellow).next().next().next().next().text(); ....

Open in new window

SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Refael

ASKER

Hi Slick812

Thank you. but you are using JavaScript which is even harder for me.
I need to print each result (e.g. YELLOW, total= 4, free= 1, sold= 3) on a different place on that page.
I do not know what to do with your code :-(
Avatar of Refael

ASKER

And it counts well the total but nothing else...
OK sorry I posted then, but the description you gave in question, said nothing about what container you need the COUNT results in, and as you said -
"I need to print each result on a different place on that page",
does not mean much to someone deciding what code operations to use to get a result.

using arrays seems like the most efficient to me
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Refael

ASKER

Hello Slick812,  Hello Julian,

Thank you, you have always been so helpful. I decided, since the the solutions were sufficient to resolve my task is to actually hook up the database and perform queries for each. Yet thank you so much, always!