vishu vishu - 1 year ago 217
Javascript Question

Yii2 load modal from on click of link

This is my _form

<div class="row">
<div class="col-sm-4">
<?= $form->field($model, 'otm_grading_system')->dropdownList(ot\TestGradingSystem::getTestGradingSystem(), [
'prompt' => Yii::t('ot', '--- Select Grading System ---'),
'onchange' => '$.get( "'.Url::toRoute('dependent/get-grading-system').'", { id : $(this).val() }).done(function(data) {
$( "#seeHere").html(data);
]) ?>
<div class="col-sm-4" id="seeHere">

In form dropDownList on change event get url. show below DependandController.php

class DependentController extends \yii\web\Controller
public function actionGetGradingSystem($id)
return Html::a('See Here 123', ['test-grading-system/view', 'id' => $id], ['id' => 'seeHereMdl', 'title' => Yii::t('ot', 'View Result')]);

And this is modal load js

"$(document).on('ready pjax:success', function() {
", $this::POS_HEAD);
'size' => 'modal-lg'

My problem is this can't load view file in modal but it redirect to this view page.

Answer Source

This is an event handling problem (not related to yii), instead of :


You should simply try :

$('body').on('click', '#seeHereMdl', function(e) {});

Read more : Event binding on dynamically created elements?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download