0

I want the user to select an option from a dropdown box either 'available' or 'not available'. If a 'not available' value is selected then I want to have the next 2 fields hidden. eg on a row in a table the user selects not available from a dropdown box then the 2 fields for the time with ids hide1 and hide2 are then hidden. Currently i cant get any detection from dropdown box selection

<script type='text/javascript'>

    function checkForOther() { 
        var e = document.getElementById("selectv"');
        var strUser = e.options[e.selectedIndex].value;

        alert (strUser);

        //hide fields

    } 
</script>

//view
<table class="table table-striped table-bordered" cellpadding="0" cellspacing="0" >
        <thead class='secondary-color-dark white-text'>
             <tr>
                <th style="width:40%">Day/Availability</th>
                <th style="width:30%">Start Time</th>
                <th style="width:30%">End Time</th>
             </tr>
        </thead>
        <tbody>
             <?php
                $availablitychoices=array(0 => 'Available',1 => 'Not Available' );
                foreach ($tutor->availability_for_tutors as $key => $item) {
             ?>
              <tr>
                 <td style='vertical-align:middle'>
                    <b><?= $item->weekday ?></b>
                    <br>
                    <?= $this->Form->input('availability_for_tutors.' . $key . '.not_available',array('label' => '', 'type' => 'select', 'options' =>$availablitychoices, 'class'=>'form-control browser-default select-input','id'=>'selectv',  'onchange' => "checkForOther(this);", 'value' => $item->available)) ?>
                 </td>
                 <td>
                    <br/>
                    <?= $this->Form->input('availability_for_tutors.' . $key . '.start_time', array('label'=>'','id'=>'hide1','default' => '9:00', 'class' => 'av_stime','interval' => 5,'timeFormat'=>12,"type"=>"time",'value'=>$item->start_time)) ?>
                 </td>
                 <td>
                    <br/>
                    <?= $this->Form->input('availability_for_tutors.' . $key . '.end_time', array('label'=>'','id'=>'hide2','default' => '10:00', 'class' => 'av_stime','interval' => 5,'timeFormat'=>12,"type"=>"time",'value'=>$item->end_time)) ?>
                 </td>
              </tr>
          <?php } ?>
     </tbody>    
</table>        
iamhuynq
  • 2,359
  • 1
  • 7
  • 27
atown99
  • 45
  • 7

0 Answers0