dimanche 22 avril 2018

Unable to pass checked value when using HTML hidden field and checkbox

I am trying to pass a boolean (int) value using two checkboxes. I have a form that is used for both adding and updating database records:

        <input type="hidden" name="isFlyerArtApproved" value="0">
        <input type="hidden" name="isPaymentReceived" value="0">
        <c:choose>
            <c:when test="${operation == 'update-order'}">
                <tr>
                    <td>Flyer art approved?</td>
                    <td>
                        <input type="checkbox" name="isFlyerArtApproved" value="1" 
                               <c:choose>
                                   <c:when test="${order.flyerArtApproved}">
                                       checked
                                   </c:when>
                               </c:choose>>
                    </td>
                </tr>
                <tr>
                    <td>Payment received?</td>
                    <td>
                        <input type="checkbox" name="isPaymentReceived" value="1" 
                               <c:choose>
                                   <c:when test="${order.paymentReceived}">
                                       checked
                                   </c:when>
                               </c:choose>>
                    </td>
                </tr>
            </c:when>
        </c:choose>

The checkboxes are only shown if the operation is to update. Regardless, I am setting a default value of 0 for each checkbox using two hidden fields. When I submit the form with any checkboxes checked, the values are still 0.

The hidden fields and the checkboxes share the same name, but for whatever reason the values of the latter do not overwrite those of the former.

I am also reading the values from the database and checking the boxes whose values are true. This works, but I can only set the values manually and not through the form.

If anyone could help, it would be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire