?
Solved

having trouble with filter() function

Posted on 2014-01-02
3
Medium Priority
?
229 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 33

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
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 invoke it on a web page. 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.: (CODE)

770 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