Cros Cros - 3 months ago 12
jQuery Question

how to send the array of the checkbox values in Jquery to rout Symfony

the majority of projects are said depend using JS (I am a beginner in the use JS).

So in my project (I use technology SF 2.7), I posted my after my BD data in a table by assigning each line with a "checkbox" button and a button "CheckAll" found in header of table for selecting my data lines.

after the search on google, I got the 1st operate CheckAll that is to say, when I click on the button "CheckAll" tres all buttons will be selected.

The only problem that remains is how to retrieve and send ids (I speak of the value of the checkbox) to my path "deleteAll"
for example if I have selected two bontons so I have to have two ids for delete.

My code html:

<!-- menu dropdown-->

<form id="deleteAll" method="post" action="{{ path('deleteAll') }}">
<strong>
<i class="fa fa-trash" ></i> Delete
</strong>
<!-- ./menu dropdown -->

<!-- table -->
<table id="datatable" class="table table-hover">
<thead>
<tr>
<th>
<input type="checkbox" id="checkAll" />
<!-- ici le bouton checkAll-->
</th>
<th>
Project title
</th>
<th>
Date Added
</th>
<th>
Modification date
</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}

<tr class="gradeC">
<td>
<input type="checkbox" id="d" name="check[]" value=" {{ entity.id }}" />
</td>
<td>
<strong>{{ entity.ProjectTitle }}</strong>
</td>
<td>
<strong>{{ entity.dateAdd |date('d-m-Y') }} </strong>
</td>
<td>
<strong>{{ entity.dateModification| date('d-m-Y H:i:s') }} </strong>
</td>
</tr>

{% endfor %}
</tbody>

</table>

</form>


-My code JS:

<script>
$(document).ready(function(){

$("#checkAll").click(function(){

var checked_status = this.checked;

$("input[name='check[]']").each(function(){

this.checked = checked_status;
var v = $("#d").val();

$('#deleteAll').on('submit', function (e){
e.preventDefault();
actiondesubsitution();
});
});

});
});


</script>


Can you help me please? I am a beginner in jQuery.

Answer

Here is the solution:

1- we must add the submit button has form.

  2- changed this code

$('#deleteAll').on('submit', function (e){ 
  ....
  });

by

$('#deleteAll').trigger('submit', function (e){ 
      ....
      });
Comments