D
D
DragonChris2017-06-23 11:31:34
Yii
DragonChris, 2017-06-23 11:31:34

Hide block after selecting some value in dropDownList YII2?

I want that after selecting "No" in the dropDownList YII2 I would hide another block

<?= $form->field($model, 'license', ['options' =>['onchange'=>'getSalutationValue'] )->dropDownList(['y' => 'Есть, 'n' => 'Нет']) ?>

Here is my js function:
function getSalutationValue() {
    		var label = this.value;
                if(label == 'n' ) {
    		document.getElementById('driver').style.display='none';
                }
    		}

But it does not work, as I understand it, the function is not called and the value is not transferred.
How to write, thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-06-23
@DragonChris

1. You are calling a function, which means you need to specify brackets i.e. not getSalutationValue but getSalutationValue()
2. Where does this come from in the function if you don't pass it? you need to pass
3. You hang the onchange event on the div that contains the drop-down list, and not on the drop-down list itself,
so you need something like this:

function getSalutationValue(value) {
    if(value == 'n' ) {
        document.getElementById('driver').style.display='none';
    }
}

<?= $form->field($model, 'license')->dropDownList([
        'y' => 'Есть', 
        'n' => 'Нет'
    ], [
        'onchange' => 'getSalutationValue(this.value)'
    ]) 
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question