Pregunta

Possible Duplicate:
How to implement “select all” check box in HTML?

Select all and Select All Category Select a category to select all and I want to run the form with jquery. But the selection process does not work in two different

I have written I do not know English using Google Translate. I wanted to do the following

Select all of the process

for example, how computing is done as follows:

Why this code does not work?

$('input[name="select_all"],input[name="select_category"]').bind('click', function(){
    var check_status = $(this).is(':checked');
    $('input[type="checkbox"]', $(this).parent('li')).attr('checked', check_status);
});


<ul>
 <li><input type="checkbox" name="select_all"> <label>Select all</label>
  <ul>
   <li><input type="checkbox" name="select_category"> <label><strong>Select All Category</strong></label>
    <ul>
     <li><input type="checkbox" name="category[]" value="1"> <label>Category 01 A</label></li>
     <li><input type="checkbox" name="category[]" value="2"> <label>Category 01 B</label></li>
     <li><input type="checkbox" name="category[]" value="3"> <label>Category 01 C</label></li>
    </ul>
   </li>
   <li><input type="checkbox" name="select_category"> <label><strong>Select All Category</strong></label>
    <ul>
     <li><input type="checkbox" name="category[]" value="4"> <label>Category 02 A</label></li>
     <li><input type="checkbox" name="category[]" value="5"> <label>Category 02 B</label></li>
     <li><input type="checkbox" name="category[]" value="6"> <label>Category 02 C</label></li>
    </ul>
   </li>
  </ul>
 </li>
</ul>
¿Fue útil?

Solución

Do you mean something like this:

//add some class to your Select All Checkbox
$('.yourCheckBoxClassHere').bind('click', function(){
    if($(this).is(':checked')) {
       $('input[name="category[]"]').attr('checked', 'checked');
    }
    else {
       $('input[name="category[]"]').attr('checked', '');
    }
});

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top