How to show field when item in drop down list is selected?


I cannot deal with one problem.

I set up the display field after selecting an item, but when I edit it, and the selected item is checked this box is not displayed.

my code:

<div class="rabaty-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'kupon')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'rabat')->textInput() ?>

    <?= $form->field($model, 'dla_wszystkich')->dropDownList([ 'Tak' => 'Tak', 'Nie' => 'Nie', ], ['prompt' => 'Wybierz']) ?>

<div id="dlakogo" style="display:none">

    <?= $form->field($model, 'dlakogo')->dropDownList(



        ) ?>


    <div class="form-group">

        <?= Html::submitButton($model->isNewRecord ? 'Utwórz' : 'Edytuj', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>


	<?php $this->registerJs(' $(\'select[id="rabaty-dla_wszystkich"]\').change(function(){

if ($(\'option:selected\').val() == "Nie")

   document.getElementById("dlakogo").style.display = "block";


   document.getElementById("dlakogo").style.display = "none";

});', View::POS_READY);


    <?php ActiveForm::end(); ?>


It works ok but during editing when the field in the database is "Nie" this field does not appear. I then manually select "Nie"

This is not Yii question but anyway…

Use this

<div id="dlakogo" style="display:<?= $model->dla_wszystkich == 'Nie' ? 'block' : 'none' ?>">

Avoid non-english names in classes and variables.