Within my form, I've included a <table>
that displays rows fetched from the database. Each row contains a checkbox, with the name attribute set to the record's ID.
The value of the checkbox changes based on its state: 1 if checked, 0 if unchecked.
When the user submits the form, I want to send the IDs of the selected rows. However, I'm unsure how to accomplish this.
<table border=1 id="mondiv" class="hidden" >
<th></th>
<th>Numero</th>
<th>Nom</th>
<th>Prenom</th>
<th>Spécialité</th>
{% for item in users %}
<tr>
<td><input type="checkbox" name="{{ item.id }}" onchange="changeetat(this)" /></td>
<td>{{ item.id }}</td>
<td>{{ item.name }}</td>
<td>{{ item.lastname }}</td>
<td>{{ item.specialty }}</td>
</tr>
{% else %}
<h2>Aucun organisateur trouvé</h2>
{% endfor %}
</table>
Below is the associated Javascript function:
function changeetat(element){
if(element.checked){
element.value = '1';
}
else{
element.value = '0';
}
}
I am using a Twig template with Symfony framework.