Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

having trouble with filter() function

Posted on 2014-01-02
3
Medium Priority
?
230 Views
Last Modified: 2014-01-02
Hello fellow EE-ers!

I'm having trouble getting the filter() function working properly. On my page, I have a table that a user can add and delete rows from. On each row, there are a series of dropdowns that are cloned every time a new row is created.

What I want to do is count up the number of team drop downs, defined by the class "chooseTeam" along with the number of goal types, defined by the class "goalType5", when the user selects an item with a value of 1.

So far I have the following:

alert ( $("select.goalType5", tbl).filter(function () { return $(this).val() == 1 && $("select.chooseTeam", tbl).filter(function () { return $(this).val() == homeTeamID }) }).length);

Open in new window


the variable tbl in this case is defined as "#tblPeriod5" and homeTeamID is a global variable set to one of the 2 team IDs that are defined in the dropdown.

my mark up for the table is as follows:

<table id="tblPeriod5">
                        
                    <tr id="row5_1">
                        <td class="col1">
                            <select class="chooseTeam" id="selScoringTeam5_1" onchange="return updateScoreboard( 5, $(this), true );">
                                <option value=''>Select Team</option><option value='129'>The All Blacks</option><option value='128'>Puck Buddies</option>
                            </select>
                        </td>
                        <td class="col2">&nbsp;</td>
                        <td class="col3">
                            <select class="scoredBy5" id="selScoredBy5_1">
                                <option value="">Attempted By</option>
                            </select>

                            <select class="goalieSO_5" id="selGoalie5_1">
                                <option value="">Opposing Goalie</option>
                            </select>
                        
                            <!--<select class="assistBy1_5" id="sel1stAssist5_1">
                                <option value="">Unassisted</option>
                            </select>
                        
                            <select class="assistBy2_5" id="sel2ndAssist5_1">
                                <option value="">Unassisted</option>
                            </select>-->
                        </td>
                        <td class="col4">
                            <select class="goalType5" id="selGoalResult5_1">
                                <option value="">Result</option>
                                <option value="1">Made</option>
                                <option value="0">Missed</option>
                            </select>
                        </td>
                            <td class="col5">
                            <a id='a5_1' href='#' onclick="return deleteRow( 5, 1 )">delete</a>
                            </td>
                        </tr>
                        
                        </table>

Open in new window


I know I'm close as I've used this method for filtering things with one  criteria, its when I add a 2nd one it doesn't return the right value.

Thanks In Advance!

Cheers
Josh
0
Comment
Question by:Big Monty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 39752600
What about :
var $selector = $("select.goalType5", tbl).filter(function () { 
      var c1 = $(this).val() == 1;
      var c2 = $(this).closest("tr").find("select.chooseTeam").val() == homeTeamID;
      return c1 && c2;
});
alert( $selector.length );

Open in new window

0
 
LVL 34

Author Closing Comment

by:Big Monty
ID: 39752627
works great, thank you!
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39752632
You're welcome!
Happy new year 2014!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question