mardi 31 octobre 2023

Checkbox created inside php foreach loop are unable to be selected

I have created a foreach loop. Everything is displayed correctly as it should. However, the issue is that the only checkbox I can select is the first row. Clicking any other check box will also select the first checkbox from the loop. I can also select a check box outside of the loop which selects all the checkboxes inside the loop.

<?php 
$count = 0;
foreach($invoiceItems as $invoiceItem){
    $count++;
    echo '
    <tr>
        <td><div class="custom-control custom-checkbox">
        <input type="checkbox" class="custom-control-input itemRow" id="itemRow">
        <label class="custom-control-label" for="itemRow"></label>
        </div></td>
        <td><input type="text" value="'.$invoiceItem["item_code"].'" name="productCode[]" id="productCode_'.$count.'" class="form-control" autocomplete="off"></td>
        <td><input type="text" value="'.$invoiceItem["item_name"].'" name="productName[]" id="productName_'.$count.'" class="form-control" autocomplete="off"></td>         
        <td><input type="number" value="'.$invoiceItem["order_item_quantity"].'" name="quantity[]" id="quantity_'.$count.'" class="form-control quantity" autocomplete="off"></td>
        <td><input type="number" value="'.$invoiceItem["order_item_price"].'" name="price[]" id="price_'.$count.'" class="form-control price" autocomplete="off"></td>
        <td><input type="number" value="'.$invoiceItem["order_item_final_amount"].'" name="total[]" id="total_'.$count.'" class="form-control total" autocomplete="off"></td>
    </tr>
    ';
}
?>



Aucun commentaire:

Enregistrer un commentaire