hi friends,
now am doing attendance of school. for attendance i want to select the class. based on that display the names of students,
here my code is
In form,
<div class="form_allign">
<?php echo $form->labelEx($model,'class'); ?>
<?php echo $form->dropDownList($model,'class',ClassLookup::items(ClassLookup::STUD_TYPE),array('class'=>'text_field1',
'onchange'=>'studentList(this.id);')); ?>
<?php echo $form->error($model,'class'); ?>
</div>
<div class="clear"></div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<script>
function studentList (id) {
var classList = document.getElementById(id).value;
alert(classList);
$.ajax({
type: 'POST', // type post
url: "<?php echo Yii::app()->createUrl('StudentDetails/viewDetails'); ?>",
data:{classList:classList}, // send id via post method
success:function(data) { // if success
alert($model);
$('#searchContent').html(data);
},
error:function(data) { // if success
alert("An internal error occurred. Please try again later...!");
},
});
}
</script>
In model
/*
* Function: attentance
* description : display student class
*/
public function actionAttendance()
{
$model = new StudentDetails;
$this->render('attendance',array('model'=>$model));
}
/*
* Function: viewDetails
* description : display student list
*/
public function actionViewDetails()
{
$classList = $_POST['classList'];
//var_dump($classList);exit;
$model = StudentDetails::model()->findByAttributes(array('class'=>$classList));
//$this->render('_view',array('search'=>$search));//var_dump($search);exit;
}
i don’t know its write or wrong. somebody help me