Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to check if the previous checkbox is checked in a jquery each function
    primarykey
    data
    text
    <p>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...</p> <pre><code>$('tbody :checked').each(function() { //row counter here if ($(this).prev("input:checkbox").is(':checked')){ </code></pre> <p>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. <br /><br /> So how can I simply just check if the first checkbox before the input box that I am in is checked or not.<br /><br /> Thanks</p> <p>edit...<br /> This is a single row...<br /></p> <pre><code>&lt;tr class="LotTableRow"&gt; &lt;td class="ColLot" colspan="2"&gt; &lt;label style="font-size: 90%; font-weight: normal; height: 10px"&gt; &lt;input checked="checked" id="3" name="BidderLot" onclick="participateOnClick(this);" type="checkbox" value="true"&gt;&lt;input name="BidderLot" type="hidden" value="false"&gt; New Lot &lt;/label&gt; &lt;/td&gt; &lt;td class="ColQuantityRow"&gt; 90 &lt;/td&gt; &lt;td class="ColStartBid"&gt; &lt;input class="text-box single-line BidderLotText" name="[0].BidderLots[0].StartBid" type="text" value="" alt="N/A" autocomplete="off"&gt; &lt;/td&gt; &lt;/tr&gt; </code></pre> <p>and this can be a group, but it can go on forever...<br /></p> <pre><code>&lt;tr class="LotTableRow" style="display:table-row"&gt; &lt;td class="ColGroup" colspan="2"&gt; &lt;input name="[2].AuctionId" type="hidden" value="c7df8b82-afa8-4709-ae08-f986523e38b9"&gt; &lt;input name="[2].LotGroupId" type="hidden" value="3cca6186-db7e-411b-975c-f97e7c10119c"&gt; &lt;label&gt; &lt;input checked="checked" id="3cca6186-db7e-411b-975c-f97e7c10119c" name="BidderGroup" onclick="participateOnClick(this)" type="checkbox" value="true"&gt;&lt;input name="BidderGroup" type="hidden" value="false"&gt; dfgdfgdfg &lt;/label&gt; &lt;/td&gt; &lt;td class="EnglishBidderLotCol"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr class="LotTableRow"&gt; &lt;td class="LotTableSpace"&gt; &lt;/td&gt; &lt;td class="ColLot"&gt; New Lot &lt;/td&gt; &lt;td class="ColQuantityRow"&gt; 20 &lt;/td&gt; &lt;td class="ColStartBid"&gt; &lt;input class="text-box single-line BidderLotText watermark" name="[2].BidderLots[0].StartBid" type="text" value="" alt="N/A"&gt; &lt;/td&gt; &lt;/tr&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload