dropdown using jquery and ajax

after selecting dropdown menu, corresponding attributes(same row) should get automatically displayed.

please give me idea to implement it.

hi Amitesh,

If you have a condition before the attributes display, you may use CHtml:ajax.

By selecting the dropdown, data will be posted to the controller method to process and return the result back to your view page.

On ajax success, you may place your jquery to control the appearance of the attributes.

Can you give me a example…I will be grateful to u!! Thank you!

On ajax success, you may place your jquery code to control the appearance of other attribute.

             $optionsdata = array(






	     $htmlOptions = array('size' => '1','empty'=>'Please Select',

						'onblur'=> CHtml::ajax(array(

						'type'=>'POST', //request type

						'url'=>$this->createUrl('controller/action'), // url to call controller action

						'success'=>' function(data) {  }',// function to call onsuccess 

							// "data" is returned data and function can be regular js or jQuery



						'class'=>'form-control', // css class



	     echo $form->dropDownList($model,'attributename', $optionsdata, $htmlOptions);


  public function actionGetdata()


          $model=  Course::model()->findAll('id=:id', array(':id'=>(int) $_POST['id']));

          //$data=  CHtml::listData($data,'id','course_details');


          //foreach($data as $value=>$course_details){

          //echo CHtml::tag('option', array('value'=>$value),CHtml::encode($course_details),true);}






public function actionCreate()


		$model=new Course;







/* @var $this CourseController */

/* @var $model Course */

/* @var $form CActiveForm */


<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(



)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row" id="drop1">

		<?php echo $form->labelEx($model,'course_name'); ?>

		<?php $type_list=CHtml::listData(Course::model()->findAll(),'id','course_name');

                echo CHtml::activeDropDownList($model,'course_name',$type_list,array('empty'=>'Select Option',




                  'update'=>'#drop2 #drop3 #drop4',





		<?php echo $form->error($model,'course_name'); ?>


	<div class="row" id="drop2">

		<?php echo $form->labelEx($model,'course_details'); ?>

		<?php echo CHtml::encode($model-> course_details); ?> 


                 <?php echo $form->error($model,'course_details'); ?>


	<div class="row" id="drop3">

		<?php echo $form->labelEx($model,'session'); ?>

		<?php echo $form->textField($model,'session',array('size'=>10,'maxlength'=>10)); ?>

		<?php echo $form->error($model,'session'); ?>


	<div class="row" id="drop4">

		<?php echo $form->labelEx($model,'is_deleted'); ?>

		<?php echo $form->textField($model,'is_deleted'); ?>

		<?php echo $form->error($model,'is_deleted'); ?>


	<div class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? 'Register' : 'Save'); ?>




<?php $this->endWidget(); ?>

</div><!-- form -->

this is my code…i think there is a lot of problem.nt understanding previous reply.

Are you trying to update attributes in div with id(#drop2,#drop3,#drop4) with the results returned by "Getdata" action ?

You may want to check out this link.


Did your query work ? May I know what is the problem that you encountered ?

What i want is whenever i select any course name from dropdownlist then its corresponding attributes(course_details,session,etc as per given in the form) should be displayed.I am not getting how to implement it.I am new to Ajax.I am not sure about code written in Getdata…Please give me idea how should i go about it.Thank you…

As well as i want to pass these attributes to another model named "StudentCourseRelation". just to display selected courses by students.That model has coures_id as a foreign key.