0

I have this table which can be very large, it contains single rows which can be selected with a tick box on the left or they can contain groups which contain their own individual rows where the group can be selected on its own to select all the individual rows in that group. Now I have a query each function which looks like this...

$('tbody :checked').each(function() {
    //row counter here
    if ($(this).prev("input:checkbox").is(':checked')){

So this checks to see what rows are checked, then in that I have this "If" statement which isnt working for me. Basically in each row I have input values however I dont want this code to run on any of the inputs where the checkbox is not selected. So in the each function I want it to check if the previous checkbox is checked and if it is then continue with the code, if not then skip it. However, I can do this easy for the individual rows, however my groups are complicated as they can contain many many table rows so I am unable to just ask for the closest table row and see if the checkbox is checked.

So how can I simply just check if the first checkbox before the input box that I am in is checked or not.

Thanks

edit...
This is a single row...

<tr class="LotTableRow">
    <td class="ColLot" colspan="2">
        <label style="font-size: 90%; font-weight: normal; height: 10px">
            <input checked="checked" id="3" name="BidderLot" onclick="participateOnClick(this);" type="checkbox" value="true"><input name="BidderLot" type="hidden" value="false">                                          New Lot
        </label>
    </td>
    <td class="ColQuantityRow">
        90
    </td>
    <td class="ColStartBid">
        <input class="text-box single-line BidderLotText" name="[0].BidderLots[0].StartBid" type="text" value="" alt="N/A" autocomplete="off">
    </td>
</tr>

and this can be a group, but it can go on forever...

<tr class="LotTableRow" style="display:table-row">
    <td class="ColGroup" colspan="2">
        <input name="[2].AuctionId" type="hidden" value="c7df8b82-afa8-4709-ae08-f986523e38b9">
            <input name="[2].LotGroupId" type="hidden" value="3cca6186-db7e-411b-975c-f97e7c10119c">
        <label>
            <input checked="checked" id="3cca6186-db7e-411b-975c-f97e7c10119c" name="BidderGroup" onclick="participateOnClick(this)" type="checkbox" value="true"><input name="BidderGroup" type="hidden" value="false">                                            dfgdfgdfg
        </label>
    </td>
    <td class="EnglishBidderLotCol">
    </td>
</tr>
<tr class="LotTableRow">
    <td class="LotTableSpace">
    </td>
    <td class="ColLot">
        New Lot
    </td>
    <td class="ColQuantityRow">
        20
    </td>
    <td class="ColStartBid">
        <input class="text-box single-line BidderLotText watermark" name="[2].BidderLots[0].StartBid" type="text" value="" alt="N/A">
    </td>
</tr>
Ben
  • 2,388
  • 4
  • 18
  • 16

2 Answers2

0

Assuming there is one checkbox inside each tr, this should work:

if ($(this).parents('tr:eq(0)').prev().find('input[type="checkbox"]:checked').length){

Your previous selector won't match, because there is no previous checkbox inside the TD element. But since you didn't post any HTML that's only my guess.

koko
  • 958
  • 12
  • 26
  • Ye something like this works for my individual rows, but when I get to my groups it doesnt work because they are all in their own "tr"s without a checkbox – Ben Jan 14 '13 at 15:32
0

Hmm, how about going about it a different way?

  1. Get each of the checked items:

    jQuery("tbody input:checkbox")

  2. Process each item

    jQuery("tbody input:checkbox").find("whatever it is your are looking for to run your code").each(function() {});

I hope this helps

Amd4632
  • 199
  • 1
  • 1
  • 8
  • Ok, I did this, but I still run into the same problem when I get to my groups. Its just hard to say you want only the text boxes within the group only – Ben Jan 14 '13 at 15:31
  • @Ben, post a snippet of your HTML that has the groups – Amd4632 Jan 14 '13 at 19:27