dimanche 8 septembre 2019

jQuery Enable/Disable input with its corresponding checkbox generated from array - Codeigniter

I'm running a loop which generates an input along with checkbox inside a form. I trying to disable input fields and enable only particular field who's checkbox is checked so only checked/enables input values get passed on submitting the form. I tried to follow this example but couldn't help my self.

$voucher array:

Array
(
    [7] => 95976X7F545
    [9] => C53DVEFCC
)

SOURCE:

<?php
foreach ($voucher as $vou) {
    if($vou['payment_voucher_code']!=''){?>
    <div class="col-lg-3">
        <span class="input-group-addon">
        <input type="checkbox" id="chk[<?php echo $vou['payment_voucher_id'];?>]"></span>
        <div>
            <input name="ex_code[<?php echo $vou['payment_voucher_id'];?>]" value="<?php echo $vou['payment_voucher_code'];?>" />
        </div>
    </div>
<?php   
    }   
}
?>

HTML:

<div class="col-lg-3">
    <span class="input-group-addon">
        <input type="checkbox" id="chk[7]">
    </span>
    <div>
         <input name="ex_code[7]" value="95976X7F545">
    </div>
</div>
<div class="col-lg-3">
    <span class="input-group-addon">
         <input type="checkbox" id="chk[9]">
    </span>
    <div>
        <input name="ex_code[9]" value="C53DVEFCC">
    </div>
</div>




Aucun commentaire:

Enregistrer un commentaire