how to insert ajax drop down in modal popup

hey guys

i create a modal popup and i want to create a from with ajax dropdwon list , but i can not add any jquery file or a ajax request?

pls help

Hey,

I’m sorry but that is way too little information.

We ne code to help you.

  • How do you open the modal in general?

  • How does the content inside the modal look like?

etc.

Best Regards




 <div class="form-inline">

                                

        <div class="form-group">

     <?= Html::button('create form', ['value' => 'url' ,

                        'id'=>'popup' , 'class' => 'btn btn-primary']);  ?>

            </div>

                                                        

                        <div class="form-group">

              <?php

                          Modal::begin([

                          'header' => '<h2>Hello world</h2>',

                          'id'     => 'modal',

                      'size'   => 'modal-lg',//size of modal

                                                        

                ]);

                                                           

                                                                

                echo "<div id='modalContent' ></div>";

                                        

                Modal::end();

                ?>

                             

         </div>

    </div>


<?php

use yii\helpers\Html;

use yii\widgets\ActiveForm;




//$this->registerJsFile('@web/js/jquery.min.js',['depends' => [\yii\web\JqueryAsset::className()]]);


?>

<!DOCTYPE html>

<html>


<body>

    <div id="page-wrapper">

        <div class="col-md-12">

           

	<div class="container">

<div class="row">

	<div class="form-inline">

	<div class="form-group">

<input class="form-control" id="xc" type="text" style="width: 200px" placeholder="xc name">

		<input class="form-control" id="xc" type="text" style="width: 200px" placeholder="xc xc">

						

								</div>							

<select id="Ctry" class="form-control" style="width: 200px;position: relative;top: 10px;">                                    

<option value="">country</option>

	<?php

	foreach( $country as $key => $value)

	{

						

										?>

	<option value="<?= $value['country_id'];  ?>"><?= $value['country_name'];  ?></option>

	<?php

		}

	?>

	</select>

																							

	<div class="form-group">								

	  <select id="ss" class="form-control" style="width: 200px">

	<option value="">city</option>

	 </select>

									</div>							

									

									

		</div>

	</div>

	<br />

	<div class="row">

<div class="">

	<div class="form-group">

		<div class="form-inline">

												

		<input type="submit" name="username" id="aa" value="Save" class="btn btn-primary" />

	</div>

	</div>

		</div>

	</div>

								

	

					</div>

                </div>

          

    </div>

</body>




<?php


$script = <<< JS




//$('#Ctry').on('change', function() {

$( "#Ctry" ).change(function() {

    

	var x = this.value;

	

//alert(x);exit;


	$.get('url' , { x : x } , function(data){

			

		

		});

});


JS;

$this->registerJs($script);


?>










rather then posting code like this try to better describe what you want to achieve and where are you stuck.

The page load?

The modal is rendere?

When you click on the button the modal open?

The modal content is shown?

As far as I understood:

you have a page with a modal:

when the modal opens it show:

[list=1][]a remote content loaded via ajax at modalshow event[]the content is already there and is a dropdown which load the options via ajax[/list]

If you posted your view file there are many errors in it

[list=1][]view should not contain header and body tags, normally these are in the template (unless it is a single page view which do not use the template)[]the modal anyway should be rendered inside the body of the page to be sure your browser properly read the tags[]if is a single page view you still miss yii2 placeholder for rendering javascript and css assets and inline script (the modal widgte render, the necessary js and css are registered but are not printed since teh placeholder are missing)[]if is a single page <html> tag is not closed[*]the javascript line $.get(‘url’ , { x : x } , function(data) is wrong since you pass the url as string, even if you pass it as variable d a url variable is not defined[/list]