mardi 6 mars 2018

Get the checkbox index in PHP

I am having a checkbox as follows,

<tr>
  <td>
     <input type="checkbox" checked="checked" name="feegroupid[]" class="fee_checkbox" value="<?php echo $fee_value->fee_groups_feetype_id ?>">
  </td>

   <td> 
      <input type="text" name="actual_pay[]" class="form-control modal_amount actual_pay" id="amount" value="<?php echo $feetype_balance; ?>">
   </td>
   </tr>

And my PHP function if the checkbox row is selected,

  foreach($_POST['feegroupid'] as $index => $selected) {

     echo $index; 

     $actualPayment = $_POST['actual_pay'][$index];      

    }

Say i have two rows with checkbox, Here the echo $index is displaying only the first row index 0 if i select the second row (whose index is 1). But both is selected (ie.checked), it is showing both index as 0,1 respectively.. But when we uncheck one checkbox(say first row with index 0 is unchecked), it is showing the 0 only but checked index is 1.

I am in the need to get the value of another input box with name actual_pay[] based on the checked box index..

Kindly help me to get the respective checked box index instead of the first row index while changing checkbox.

Attached image has a button click to pay which should send the checked box index (ie, second box is checked and its index is 1).

enter image description here




Aucun commentaire:

Enregistrer un commentaire