Answer the question
In order to leave comments, you need to log in
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' => 'Нет']) ?>
function getSalutationValue() {
var label = this.value;
if(label == 'n' ) {
document.getElementById('driver').style.display='none';
}
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question