Identify selected checkbox

Asked

Viewed 410 times

0

Good guys I have a page (view) that makes a select of the bank and returns me the registered images for the user select a limit of photos determined by the administrator most wanted to count and show to the user how many photos he can still select, that is, when it selects an image (a checkbox) it subtracts 1 from the limit and vice versa, I will leave the view code for you to understand better

        <div class="tab-content">
                <div class="tab-pane active" id="select">
                    <h4 class="info-text"> Selecione suas <b id="contafotos">10</b> fotos: </h4>
                    <div class="row">
                    <?php foreach ($for_fotos as $dados) : ?>
                      <div class="col-sm-6 col-md-4">
                        <div class="thumbnail">
                          <img src="<?php echo base_url($dados['path'].'/'.$dados['nome']); ?>" alt="<?php echo $dados['nome'] ?>">
                          <div class="caption">
                            <p>
                              <div class="checkbox">
                                <label>
                                  <input class="limited" type="checkbox" value="">
                                  Selecionar
                                </label>
                              </div>
                            </p>
                          </div>
                        </div>
                      </div>  
                    <?php endforeach; ?>  
                    </div>
                </div>
            </div>
            <div class="wizard-footer">
                    <div class="pull-right">
                        <input type='submit' class='btn btn-next btn-fill btn-warning btn-wd btn-sm' value='PRÓXIMO' />
                        <!--<input type='button' class='btn btn-finish btn-fill btn-warning btn-wd btn-sm' name='finish' value='Finish' />-->
                    </div>
                    <div class="pull-left">
                        <?php echo anchor('selecao/voltar', 'Voltar', 'class="btn btn-previous btn-fill btn-default btn-wd btn-sm"'); ?>
                    </div>
                    <div class="clearfix"></div>
            </div>
            <?php echo form_close(); ?> 
    </div>

    <script type="text/javascript">
      var selec = 10;
      $('input[type=checkbox]').on('change', function () {
        var total = $('input[type=checkbox]:checked').checked;

        if ($('input[type=checkbox]:checked')) {
            //$(this).attr("checked")=="checked"
            selec--;
        }
        $("#contafotos").html(selec);
      });
    </script>
  • This answer answers you?

1 answer

1

$('#list :checkbox').change(function(){
    $('#list :checkbox').each(function(){
        if($(this).is(':checked')){
            /** 
            *Faz o que desejar quando o checkbox estiver marcado
            */
        }
    });
});

What he does: whenever a checkbox that is inside the div #list is modified I go through all the checklists and check if it is checked if I do any action.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.