Hi, i have a check box list, based on the selection of the check box want to display different drop down list, and the values are fetch from the controller. My view is,
<?php
echo $form->radiobuttonList($model, 'category',
AdminLookup::items('NewsCategory'),
array('separator'=>'',
// 'onclick'=>'selectSubGroup',
'onchange'=>'javascript:selectSubGroup(this.value);',
'template'=>'<div style=" float:left;
width:110px;
font-size:11px; ">{input} {label}</div>'
?>
Drop Down List
<div id="industryDiv" style="display: none;">
<?php
echo $form->dropDownList($model, "sub_category",
// IndustryLookup::items(),
array(
// 'prompt'=>'Choose an Industry',
'multiple'=>'multiple', 'class'=>'txt-drop-list',
'style'=>'width: 200px;font-size:12.5px;',));
?>
</div>
This is my script: selectSubGroup
function selectSubGroup(value) {
var group = value;
if(group==1) {
$('#industryDiv').toggle();
$.ajax({
type: 'POST', //type Post
url: '<?php echo Yii::app()->createUrl("//news/Sub"); ?>',
// data:{result:group},
success:function(data) {
alert(data);
// var resultObj = $.parseJSON(data);
$('#News_sub_category').val(data);
},
error: function(data) { // if error occured
alert("Error occured...!")
},
dataType:'html' // return html type
});
}
else if(group==2) {
// other action
}
else if(group==3) {
// other action
}
else {
alert("There is no value;")
}
}
Controller action is:
public function actionSub(){
$sub_category = array();
$info = IndustryLookup::model()->findAll();
foreach ($info as $value) {
$sub_category = $value->type;
// var_dump($sub_category);
echo CJSON::encode($sub_category);
}
}
When am trying this i’m getting the values in the data on success. but is not applied to the drop down list.
When i’m trying as below method, after parseJSON i’m getting only the object object as result.
public function actionSub(){
$info = array();
$info['sub_group'] = IndustryLookup::model()->findAll();
echo CJSON::encode($info);
}
[html]$.ajax({
type: 'POST', //type Post
url: '<?php echo Yii::app()->createUrl("//news/Sub"); ?>',
// data:{result:group},
success:function(data) { // if success
alert(data);
var resultObj = $.parseJSON(data); // getting result obj and assign to new variable
alert(resultObj.sub_group);
// alert(resultObj.model);
$('#News_sub_category').val(data);
},
error: function(data) { // if error occured
alert("Error occured...!")
},
dataType:'html' // return html type
});[/html]
Please any one help me, how to assign values to the dropdown list…