samedi 10 octobre 2020

Is there is any way to change a checkbox's value when checked?

I have a table which in each cell there is a checkbox. How do I initialize the value of each cell to 'false' (also when not checked), and when the checkbox is checked the value changes to 'true' and also the background color of the cell.

Then how do I append the value of each cell to the (req.body) to send to the server?

Appreciate any help! thanks!

This is a row I have with the checkboxes for example:

<tr>
    <td class="shift active left-border"><input type="checkbox" class="checkbox" 
        name="saturdayMorning"></td>

    <% const d = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday'] %> 

    <% for(let i = d.length-1; i > -1; i--) { %> 

    <td class="shift active"><input type="checkbox" class="checkbox" value="yes" 
        onclick="change()" name="<%= d[i] %>Morning"></td>
    <% } %>

    <th class="day-part">Mornings</th>
</tr>



Aucun commentaire:

Enregistrer un commentaire