disable select in cakephp

Asked

Viewed 32 times

1

I have 2 selects, and want to make sure that when one of the select is with a different empty option, the other select enter disable.

Follows my code:

<script type="text/javascript">
 function handleSelect() {
 if (this.value == '30') {
     document.getElementById('agente_id').disabled = true;
 } else {
     document.getElementById('agente_id').disabled = false;
 }
 }
  </script>
  <div class='container'>
<form method="get" action="/financeiro/gerar_relatorios">
<div class='panel panel-primary'>        
    <div class='panel-heading'><B>FILTRAR COMISSÕES POR PERÍODO</b></div>        
    <div class='panel-body'>       
        <div class='row'>
            <div class='col-xs-6'>
                <?= $this->Form->input('data_inicio', array('class' => 'form-control mask_date','value'=> @$_GET['data']['data_inicio'])); ?>
            </div>
            <div class='col-xs-6'>
                <?= $this->Form->input('data_fim', array('class' => 'form-control mask_date','value'=> @$_GET['data']['data_fim'])); ?>
            </div>
        </div>
        <div class='row'>
            <div class='col-xs-6'>
                 <?= $this->Form->input('colaborador_id', array('class' => 'form-control','empty'=>'Filtrar todos colaboradores','value'=> @$_GET['data']['colaborador_id'])); ?>
            </div>
            <div class='col-xs-6'>
                 <?= $this->Form->input('agente_id', array('class' => 'form-control','empty'=>'Filtrar todos agentes','value'=> @$_GET['data']['agente_id'])); ?>
            </div>
        </div>
        <div class='row'>
            <div class='col-xs-6'>
                 <?= $this->Form->input('compra', array('class' => 'form-control','placeholder' => 'Filtre pelo número da compra','value'=> @$_GET['data']['compra'])); ?>
            </div>
        </div>
    </div>        
    <div class='panel-footer'>
        <?= $this->Form->submit('Filtrar', array('class' => 'btn btn-info')); ?>
    </div>        
</div>
</form>

My question is, how to instantiate this function js in select?

1 answer

2


Try it this way:

<?= $this->Form->input('compra', 
                    array('class' => 'form-control',
                          'placeholder' => 'Filtre pelo número da compra',
                          'value' => @$_GET['data']['compra'], 
                          'onchange' => "handleSelect(this);")
                   ); ?>
  • I did it this way, but when I select the option value is 30, select agente_id, remains qualified.

  • ok, but he is entering the handleSelect function ? if he is seeing what comes in this.value and post here

  • I’m trying to debug in firebug, but the console shows nothing.

  • put a console.log inside the function before the condition

  • this way? function handleSelect() {&#xA; console.log(this);&#xA; if (this.value == '30') {&#xA; document.getElementById('agente_id').disabled = true;&#xA; }&#xA; }

  • @Michelhenriq this, just to see if you are entering the function, if you are entering and give me the return

  • On the console nothing appears, and I let the other select disabled, and I select the option that has the value 30, and select does not quit the disabled..

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.