How to do a SelectAll checkbox

0

I need to create a checkbox if it is selected it will select all the others and if it is not selected the others should also be deselected.

I tried to do something but it did not work. See:

$("#selectAll").on('checked', function () {
   $(".checkReunioes").each(function( index ) {
      $( this ).attr("check", "checked");
   });
});

Select All :

<li class="item item-checkbox colorCheck">
   <label class="checkbox checkbox-dark">
      <input type="checkbox" id="selectAll">
   </label>
   <div id="nameSelectAll"></div>
</li>

Remaining of the checkbox inputs are dynamically generated .

'<li class="item item-checkbox">'+
'  <label class="checkbox">'+
'       <input type="checkbox" class="checkReunioes">'+
'     </label>'+
'  <div data-uib="layout/card" data-ver="0">'+
((reunioes[i].COD_PESSO_LOCAL == "999") ? '<div class="">'+ reunioes[i].TXT_DESCR_ENDER +'</div>' : '<div class="">Casa '+ ((w_elemento == "M") ? "do " : "da ")+''+ reunioes[i].TXT_LOCAL_REUNI +' </div>')+
'   <div class="card_Data">'+DataInvertida+'</div>'+
'     <input id="codigoReuniao" value="'+reunioes[i].COD_IDENT_REUNI+'" hidden/>'+
'   </div>'+
'</li>' 
    
asked by anonymous 23.10.2015 / 19:51

1 answer

1

Renan, do so.

$("#selectAll").on('change', function () {

   var checked = this.checked;

   $(".checkReunioes").each(function(index, val) {

      $(this).prop("checked", checked);
   });
});

link

******** EDITED

To change the text according to the action.

First of all, we'll change the structure of HTML by adding a span tag.

   <label class="checkbox checkbox-dark"> 
      <span class="textoSelecionarTodos">Selecionar todos</span>
      <input type="checkbox" id="selectAll">
   </label>

And now our javascript looks like this

//isso é para otimizar e não fazer o jQuery buscar o mesmo elemento toda vez que o checkbox mudar
var $selectAllText = $('span.textoSelecionarTodos');

$("#selectAll").on('change', function () {

   var checked = this.checked;

   if(checked) {
       $selectAllText.text('Desmarcar todos');
   }
   else {
       $selectAllText.text('Selecionar todos');
   }

   $(".checkReunioes").each(function(index, val) {

      $(this).prop("checked", checked);
   });
});

Follow example

link

    
23.10.2015 / 20:01
Incorrect syntax near '-' in Insert ___ ___ erkimt manage Multiple WindowsForm SplitContainer ______ qstntxt ___

I have multiple windowsforms inside a SplitContainer, one of them, I have a ListBox.

That is, outside the SplitContainer, on Form1, has button, when I click it, I want to add a text in the ListBox inside the SplitContainer on Form2

When I click the button, nothing happens! < Here is the error.

Form1Load:

%pre%

Button1code(ERRORishere):

%pre%    
______azszpr94312___

Of course it will not add, you are using %code% as if it were a static member, when re-creating the object with %code% will appear the item that you defined. It's like a pre-addition.

To solve this you should create a reference to the created member, follow the example below:

%pre%

To add the item to the ListBox, do the following:

%pre%     
___