mardi 9 mai 2017

Cakephp: Enabling/Disabling textbox when checkbox being checked/unchecked

Need Help to Solve This!

Using Cakephp, I do listing that displays name(some text), checkbox and textbox. What I need is when the checkbox is being checked, the textbox should be enabled, otherwise it should be disabled. I tried out. but it is not working as i desire.

Here is the code and its jquery.

    <tbody>
          <?php $count = 0; ?>
          <?php foreach ($get_resources['learnings'] as $learnings): ?>
               <tr><td>
                  <?php $control_id = $this->SDNTextUtils->cleanCssIdentifier($learnings['name']); ?>

          <div class="switch">
        <?= $this->Form->label($control_id, __($learnings['name'])); ?></div></td>
    <td>
     <div class="switch">
    <?= $this->Form->checkbox("lrng_permission[$count][permission]", ['class' => 'cmn-toggle cmn-toggle-round', 'id' => $control_id, 'name'=>'idd']); ?>


     <?= $this->Form->label($learnings['name'], ''); ?>



    <?= $this->Form->hidden("lrng_permission[$count][resource_name]", ['value' => $learnings['name']]); ?> 

    <?= $this->Form->hidden("lrng_permission[$count][resource_type]", ['value' => 'Learning']); ?></td>

    <td> <?= $this->Form->number('',['label'=>false,'id'=>'check1','disabled' => 'disabled']); ?>

    </td></tr>
    </div>

<?php $count ++; ?>
<?php endforeach; ?>
    </tbody>

//Here is the JQuery

<script src="http://ift.tt/1oMJErh"></script>
<script type="text/javascript"> 


    $('#idd').'change',function(){
       var checked=$('#idd').is(':checked');
        if(checked==true)
        {   
            $('#check1').attr('disabled',false);
        } else {

            $('#check1').attr('disabled',true);
        }
      });

</script>




Aucun commentaire:

Enregistrer un commentaire