Note that there are some explanatory texts on larger screens.

plurals
  1. POcheck uncheck All checkboxes and count values using data attributes
    primarykey
    data
    text
    <p>I want to check all the check oxes and calculate the values consisted in the data attributes:-</p> <pre><code>&lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th style="text-align: center;"&gt;Pay? &lt;input class="chkSelectAllTimeLogs" type="checkbox" /&gt; &lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; @for (int i = 0; i &lt; 10; i++) { &lt;tr&gt; &lt;td style="text-align: center;"&gt; @Html.CheckBoxFor(model =&gt; Model.timeLogCollection[i].IsCheckedTimeLog, new { @class = "timeLogItem", data_amount = i } ) &lt;/td&gt; &lt;/tr&gt; } &lt;/tbody&gt; &lt;/table&gt; &lt;div id="divTotalAmount" style="text-align: center; font-size: 30px; font-family: Tahoma; font-weight: bold;"&gt; 0.00 &lt;/div&gt; </code></pre> <p>What i want is when i click on the the check box with class "chkSelectAllTimeLogs" then 1. All the checkboxes with class "timeLogItem" should be checked 2. The values in the data-amount should be calculated accordingly i.e. on check and uncheck of click of single or multiple.</p> <p>Currently i have 2 separate functions working as follows:</p> <p>to mark the check all i have:</p> <pre><code>jQuery(".chkSelectAllTimeLogs").click(function () { if (jQuery(".chkSelectAllTimeLogs").is(':checked')) { jQuery(".timeLogItem").prop("checked", true); } else { jQuery(".timeLogItem").prop("checked", false); } }); </code></pre> <p>to calculate the total i have:</p> <pre><code>function ehRunningTotalForTimeLogPaymentEntry() { /* This event handler monitors the checkboxes for time log items and updates the running total in a DIV. */ var total = 0; jQuery(".timeLogItem").click(function () { var amount = jQuery(this).data("amount"); if (this.checked) { total += amount; } else { total -= amount; } jQuery('#divTotalAmount').html(total).formatCurrency(); }); } </code></pre> <p>both the functions are in document ready. Please let me know how can i accomplish this?</p> <p>Regards Abhishek</p>
    singulars
    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