Control script when the user chooses multiple checkboxes
<p>I have created a php form with multiple checkboxes and there is a script that controls if the sum (sum of all checkboxes values) is greater than a specific number.If yes, a sweetalert box appears.The problem is that when I click the 'OK' button on the sweetalert I want to remove the last checked attribute and to remove that value from the sum to execute the script again and display the right results.I cannot figure this out..Any ideas will be helpful!</p>

<p>Script :</p>

<pre><code> var sum = 0; 
    var maxSum = &lt;?php echo $form_points;  ?&gt; ; 

    $('[name="opt"]').change(function(){

      if($(this).is(":checked")) {
        sum = sum + parseInt($(this).val()); 
      }
      else
      {
        sum = sum - parseInt($(this).val()); 
      }
      if( sum &gt; maxSum )
      {

          //$('#checkbox').prop('checked',prop);
          sweetAlert("ΠΡΟΣΟΧΗ", "Υπερβήκατε τους πόντους του πελάτη", "error"); //your alert message

        $("#checkbox").click();

      }

    })
</code></pre>

<p>For example : If the specific number is 500 and the sum is 550(1st checkbox value=200 + 2nd checkbox value=200 + 3rd checkbox value=150) and after I click on 'OK' then the script must removes the 3rd checkbox value from the sum (so sum must be now 400) and unchecks the the checkbox..</p>

<p>form with checkboxes :</p>

<pre><code> echo '

  &lt;div&gt;
   &lt;div class="feed-activity-list"&gt;
     &lt;div style="border: 0.5px solid green; border-right-style:none;" class="input-group m-b"&gt;&lt;span class="input-group-addon"&gt;   &lt;input type="checkbox" name="opt" value="'.$points.'"&gt;&lt;/span&gt;
        &lt;div class="feed-element"&gt;
          &lt;a href="profile.html" class="pull-left"&gt;
          &lt;img alt="image" class="img-circle" src="'. $row_select4['image_url']. '"&gt;
          &lt;/a&gt;
        &lt;div class="media-body "&gt;
          &lt;div class="ibox-tools"&gt;
              &lt;span class="label label-primary"&gt;ΔΙΑΘΕΣΙΜΟ&lt;/span&gt;&lt;br&gt;&lt;br&gt;
              &lt;span class="label label-warning-light pull-right"&gt;&lt;strong&gt;'  .$row_select4['points'].  '&lt;/strong&gt; Πόντοι&lt;/span&gt;
          &lt;/div&gt;
              &lt;strong&gt;'  .$row_select4['title'].  ' &lt;/strong&gt; '   .$row_select4['description'].  ' &lt;br&gt;
              &lt;small class="text-muted"&gt;Διάρκεια: &lt;strong&gt;'  .$row_select4['start_date'].  ' - '   .$row_select4['end_date'].  ' &lt;/strong&gt;&lt;/small&gt;
          &lt;div class="well"&gt;
                                                    '  .$row_select4['description'].  '
       &lt;/div&gt;
     &lt;/div&gt;
   &lt;/div&gt;
 &lt;/div&gt;

&lt;/div&gt; ';
</code></pre>