platanas20 platanas20 - 4 months ago 4x
PHP Question

Alert message when sum of checkboxes is greater than a specific number

I need your help with something I am trying to create.What I want to build is an alert message displaying to user screen when the sum of the values of the checkboxes is greater than a specific number which is stored in the database table.The thing is that I am using php to echo the checkboxes form..

Here is the form:

echo '

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

</div>' ;

And the submit button (outside the php script):

<button type="submit" class="btn btn-w-m btn-primary">ΕΞΑΡΓΥΡΩΣΗ</button>


You could use a jquery script on the bottom of the page.

var checkboxes = $('.feed-activity-list input[type=checkbox]');
var sum;

checkboxes.on('change', function() {
  sum = 0;

  checkboxes.each(function(key, input){
    sum += (input.val() - 0);

  if (sum > 9999999) {
    alert('input too big');

And put the sum in a hidden input.