zii.widgets.jui.CJuiDatePicker ajax age

Hello

I’m using Yii 1

For some time, I am reviewing forums, videos and web pages to calculate the age of a person with zii.widgets.jui.CJuiDatePicker through ajax.

When calculating age, I need to retrieve this age in a textField of the same form.

The function of the controller, I made a debug calculates the age well, but at the moment of returning it to the textField the data is lost.

I have done everything possible, attached the source code.

Please, someone who can guide me.

Thank You

Form Code:

<tr>


	<td>	


	<div class="row">


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


		<?php	


		$this->widget('zii.widgets.jui.CJuiDatePicker',


				array(


				'model'=>$model,


				'attribute'=>'gdg_fecha_nacimiento',


				'name'=>'gdg_fecha_nacimiento',


				'language'=>'es',


				'options'=>array(


					'dateFormat'=>'dd/mm/yy',


					"changeYear" => true,


					"changeMonth" => true,


					'yearRange' => '-80:-10',


					'defaultDate'=> '01/01/1999',


					'onSelect'=> 'js: function(dateText, inst) {'.


							CHtml::ajax(array('type'=>'POST',


											  'datatype'=>'json',


											  'url'=>Ccontroller::createUrl('AsisGaranteDatosGenerales/Calcula_Edad'),





									 'success'=>"function(data){


									  $('#AsisGaranteDatosGenerales_gdg_edad').val(data.edad_calc);


									  


            						$('#AsisGaranteDatosGenerales_gdg_edad div.divForForm form').val(data.edad_calc);





									   }",


											) //array


															 


								      ).


							'}'


								


						), //options





					


					)//array


				


				); //zii


		?>


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


	</div>


	</td>


	<td>


	<div class="row"> 


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


		<?php echo $form->textField($model,'gdg_edad',array('size'=>18,'maxlength'=>18,'readonly'=>true)); ?>


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


	</div>


	</td>


</tr>

Controller Code:

public function actionCalcula_Edad()


{


	$fecha = $_POST['AsisGaranteDatosGenerales']['gdg_fecha_nacimiento'];


	list($d,$m,$Y) = explode("/",$fecha);


	$edad=( date("md") < $m.$d ? date("Y")-$Y-1 : date("Y")-$Y );





     echo CJSON::encode(array('edad_calc'=>$edad));


	 Yii::app()->end();





}

Ok,

I succes solution.

Add code:

form code:

<tr>


	<td>	


	<div class="row">


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


		<?php	


		$this->widget('zii.widgets.jui.CJuiDatePicker',


				array(


				'model'=>$model,


				'attribute'=>'gdg_fecha_nacimiento',


				'name'=>'gdg_fecha_nacimiento',


				'language'=>'es',


				'options'=>array(


					'dateFormat'=>'dd/mm/yy',


					"changeYear" => true,


					"changeMonth" => true,


					'yearRange' => '-80:-10',


					'defaultDate'=> '01/01/1999',


					


					'onSelect'=> 'js: function(dateText, inst) {'.


							CHtml::ajax(array('type'=>'POST',


											  'datatype'=>'json',


											  'url'=>Ccontroller::createUrl('AsisGaranteDatosGenerales/Calcula_Edad'), 


										 'success'=>"function(data){


										  //alert(data);


										  $('#AsisGaranteDatosGenerales_gdg_edad').val(data);


										   }",


											) //array


															 


								      ).


							'}'


								


						), //options


					


					)//array


				


				); //zii


		?>


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


	</div>


	</td>


	<td>


	<div class="row"> 


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


		<?php echo $form->textField($model,'gdg_edad',array('size'=>18,'maxlength'=>18,'readonly'=>true)); ?>


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


	</div>


	</td>


</tr>

AND Controller Code:

public function actionCalcula_Edad()


{


	$fecha = $_POST['AsisGaranteDatosGenerales']['gdg_fecha_nacimiento'];


	list($d,$m,$Y) = explode("/",$fecha);


	$edad=( date("md") < $m.$d ? date("Y")-$Y-1 : date("Y")-$Y );


	 echo $edad;


	 Yii::app()->end();





}