Solved

having trouble with filter() function

Posted on 2014-01-02
3
224 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
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
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 32

Author Closing Comment

by:Big Monty
Comment Utility
works great, thank you!
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
You're welcome!
Happy new year 2014!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now