MALKI MOHAMED MALKI MOHAMED - 2 months ago 66
Javascript Question

onchange function in dropDownList yii2

I have a function (getArticleByFamille) in event onchange dopDownList like this:

<?= $form->field($modelFamille, 'idFamille')->dropDownList(
ArrayHelper::map(Famille::find()->all(), 'idFamille', 'libelle'),
[
'prompt' => 'Sélectionner la Categorie',
'class' => 'chosen-select mb-15',
'onchange' => 'getArticleByFamille(this.value,"vente/devis","' . Yii::$app->getUrlManager()->getBaseUrl() . '","ArticleByFamille")'
]
)->label(false); ?>


but When I call this function, it not working and when I inspect I have this code:

onchange="getArticleByFamille(this.value,&quot;vente/devis&quot;,&quot;/performancia/web&quot;,&quot;ArticleByFamille&quot;)"


quote was changed

Answer

It is because occurs encoding (enabled by default).

Try this (not tested):

[
    'prompt'   => 'Sélectionner la Categorie',
    'class'    => 'chosen-select mb-15',
    'onchange' => new \yii\web\JsExpression( 'getArticleByFamille(this.value,"vente/devis","' . Yii::$app->getUrlManager()->getBaseUrl() . '","ArticleByFamille")' )
]