Hi to all!
I’m new in this forum and in the use of yii2.
I installed yii2 advanced from zip file, I created a form with a dependence dropdown, I think that it should work fine if it wasn’t be a problem with the url: if I put in the browser url the link http://localhost/testing/frontend/web/index.php?r=site%2Flists-provincie&IDRegione=6 it works as it should, but the link created from the onchange (http://localhost/testing/frontend/web/index.php?r=site%2Flists-provincie%26IDRegione%3D6) doesn’t work.
My code is the following:
<?= $form->field($model, 'Provincia')->dropDownList(GetCountries::getProvincie(),['prompt' => '','id' => 'provincia'])->label('Provincia') ?>
and at onchange the browser returns “not found”.
Can someone help me?
Mic
How do you create url in onchange
event? Add that part also
Sorry, I writed the wrong code
This is the right one:
<?= $form->field($model, 'Regione')->dropDownList(GetCountries::getRegioni(),['prompt' => '','onchange' => '$.post("'.Yii::$app->urlManager->createUrl('site/lists-provincie&IDRegione=').'"+$(this).val(), function(data) {$("select#provincia").html(data);});'])->label('Regione') ?>
In my SiteController.php there is the public actionListsProvincie($IDRegioni) and works fine in the url of the browser but not from the script
bpanatta
(Bruno Panatta)
5
Pass values as parameters and add /
(slash) before the site
:
Yii::$app->urlManager->createUrl('/site/lists-provincie, 'IDRegione' => '')
You could also replace the Yii::$app->urlManager->createUrl()
with \yii\helpers\Url::to()
.