I am new to Yii. I have a javascript variable. This ID must be passed to the controller and to the respective view also. I have a problem in accessing the JS variable in the controller. Please help me. If the JS variable is passed, how will I check the passed variable.? Thanks in advance,
My view from where JS variable(id) is passed:
<div style="float:left;padding-left:20px;">
<?php echo $form->labelEx($model,'host_customer_id'); ?>
<?php
echo $form->textField($model,'host_customer_id',array('style'=>'width:420px;'));
$this->widget('ext.select2.ESelect2', array(
'selector' => '#NimsoftHost_host_customer_id',
'options' => array(
'allowClear'=>false,
'placeholder' => 'Search Other Customers',
'minimumInputLength' => 3,
'quietMillis'=>100,
'ajax' => array(
'url' => Yii::app()->createUrl('Nimsoft/customers'),
'dataType' => 'jsonp',
'data' => 'js: function(term,page) {
return {
q: term,
//ctype: $("#itsmIncidents_cloudcustomer input:radio:checked").val(),
page_limit: 10,
};
}',
'results' => 'js: function(data,page){
return {results: data.details};
}',
),
'formatResult' => 'js:function(data){
return data.name;
}',
'formatSelection' => 'js: function(data) {
return data.name;
}',
),
));
?>
<div style="float:right;padding-left:10px;">
<?php
echo CHtml::link('view details', array('/Nimsoft/ciLink'), array(
'onclick'=>'return hs.htmlExpand(this, { objectType: "iframe", wrapperClassName: "full-size",height:500, align: "center" } )',
'class'=>'btn btn-block btn-success',
'style'=>'width:100px;display:none;',
'id'=>'customer_details_pop',
));
?>
</div>
</div>
<?php $this->endWidget();?>
<script>
$("#NimsoftHost_host_customer_id").on("change", function(e) {
<?php echo CHtml::ajax(array(
'url'=>array('Nimsoft/loadCustType'),
'data'=> "js:{'NimsoftHost[host_customer_id]':e.val}",
'type'=>'post',
'dataType'=>'json',
'success'=>"function(data)
{
// enable customer link
$('#customer_details_pop').css('display','block');
$('#customer_details_pop').attr('href', 'Nimsoft/details/'+data.customerid);
} ",
))?>;
})
</script>
here I am passing data.customerid. I want to know this value goes to controller or not. If it goes, how to print that in my view(details.php).
My controller action:
public function actionDetails()
{
$this->render('details');
}