Help I have problem with a div

0

Good day, I am forced to request your help, I consult you I have a form that I have the following

<?= $form->field($model, 'cd_categoria',['labelOptions'=>['style'=>'color:black']])->dropdownList($model->getListaCategoria(), ['prompt' => '---Seleccione Categoria---',

['maxlength'=>50,'style'=>'width:500px; color:black; ',
'onChange'=>'
$.post("list?id='.'"+$(this).val(), function(data) {
if(data=="1"){
$( "#result" ).show();
}else{
$( "#result" ).hide();
}


});']]) ?>
<div id="result" style="display:none;">
<?= $form->field($model, 'nu_personas',['labelOptions'=>['style'=>'color:black']])->textInput([['maxlength'=>50,'style'=>'width:500px; color:black; ']]) ?>
</div>

public actionList($id){
if($id==19){
echo "1";
}else{
echo "0";
}

}

What I need to do is that when I select the div, a specific option shows me the div below that of the '' nu_personas '' and if I do not continue showing it, someone can tell me what may be happening

    
asked by Sebastian Salazar 14.03.2018 в 18:29
source

2 answers

0

From what I see the Form above is always being written, you have to put a conditional to show one or another Form.

<?=
**if (mostrar) {**
$form->field($model, 'cd_categoria',
['labelOptions'=>  
['style'=>'color:black']])->dropdownList($model->getListaCategoria(),  
['prompt' => '---Seleccione Categoria---',
}
    
answered by 14.03.2018 в 18:40
0

This works well for me.

Controller TestController.php

  public function actionList($id)
    {
        if ($id == 1) {
            echo "1";
        } else {
            echo "0";
        }

    }

View test / index.php

  <?= Html::dropDownList(
    'testName',
    '2',
    [
        'none' => "Nothing",
        '1' => '1',
        '2' => '2',
        '3' => '3',
        '4' => '4',
    ],
    [
        'maxlength' => 50,
        'style' => 'width:500px; color:black; ',
        'onChange' => '
        $.post("list?id=' . '"+$(this).val(),
             function(data) {
                console.log(data);
                if(data=="1"){
                    $( "#result" ).show();
                }else{
                    $( "#result" ).hide();
                }           
            }
        );'
    ]) ?>


<div id="result" style="display:none;">
    aaa
</div>
  

The title of your function should be public function actionList ($ id) and not public actionList ($ id)

    
answered by 26.03.2018 в 13:01