在MyajaxController
:
public function actionGetDropDownInfo(){
$selected_drop_down_val = $_POST['ddl']; // the drop down list's changed value
$article = "..."; // what you have to process with corresponding to $selected_drop_down_val
$drawing = "..."; // what you have to process with corresponding to $selected_drop_down_val
$variant = "..."; // what you have to process with corresponding to $selected_drop_down_val
echo json_encode(array(
'article' => $article,
'drawing' => $drawing,
'variant' => $variant
));
Yii::app()->end();
}
在您的表单中,添加一点 jQuery:
<script>
$(function(){
$('#drop_down_list_id').on('change', function (e) {
//var optionSelected = $("option:selected", this);
var selectedValue = this.value;
$.ajax({
type: "POST",
url: "<?php echo Yii::app()->createUrl('Myajax/GetDropDownInfo')?>",
data: {ddl: selectedValue}, //post a selected value of drop down list
dataType: 'json',
beforeSend: function () {$('.loading-icon').show();},
complete: function () {$('.loading-icon').hide();},
success: function (data) {
// bind returned data into your fields
$('#article-field-id').val(data['article']);
$('#drawing-field-id').val(data['drawing']);
$('#variant-field-id').val(data['variant']);
}
});
});
</script>
以上是如何实现您的观点的想法之一。我认为您的问题与 Yii 没有太大关系,如果您按标签搜索form
,jQuery
或者ajax
,您可以找到已提出的其他解决方案。