简体   繁体   English

如何在ajax中传递下拉值?

[英]how to pass the dropdown value in ajax?

This may be silly question but i dono.... 这可能是个愚蠢的问题,但我不知道。

            <div class="row">
            <?php echo $form->labelEx($stmodel,'student_track_class_branch',array('class'=>'col-md-4 control-label')); ?>       
            <div class="col-md-4">          
                <?php
                    $start_class=Yii::app()->user->getState('start_class');
                    $end_class=Yii::app()->user->getState('end_class');

                    $std_arr=array();
                    for($i=$start_class; $i <= $end_class; $i++)
                        $std_arr[$i]=$i.' Std';
                    echo $form->dropdownlist($stmodel,'student_track_class_branch',
                                    $std_arr,
                                    array(  'empty'=>'--Select--',
                                            'class'=>'form-control',
                                            'required'=>"required",
                                            'ajax'=>array('type'=>'POST',
                                                        'url'=>CController::createUrl('common/UpdateSectionView'),
                                                        'data'=>array('std_id'=>'js:$(this).val()','YII_CSRF_TOKEN' => Yii::app()->request->csrfToken),
                                                        'update'=>'#StudentTracker_student_track_sec_dept'
                                                        )
                                        )
                                    );
                ?>
                <?php echo $form->error($stmodel,'student_track_class_branch'); ?>
            </div>
        </div>
        <div class="row">
            <?php echo $form->labelEx($stmodel,'student_track_sec_dept',array('class'=>'col-md-4 control-label')); ?>
            <div class="col-md-4">
                <?php 
                    $sec_arr=array();
                    if(!empty($stmodel->student_track_class_branch))
                    {
                        $sec=new SchoolSectionDetails;
                        $sec_avl = $sec->get_section_limit( Yii::app()->user->role, Yii::app()->user->id, $stmodel->student_track_class_branch);

                        $sec_arr  = array();
                        if (!empty($sec_avl))
                        {
                            for ($i = 1; $i <= $sec_avl; $i++)
                                $sec_arr[$i] = $this->_school_sec[$i];
                        }
                    }
                    echo $form->dropdownlist($stmodel,'student_track_sec_dept',$sec_arr,
                                                array('empty'=>'--Select--','class'=>'form-control','required'=>"required",)); 
                ?>
                <?php echo $form->error($stmodel,'student_track_sec_dept'); ?>
            </div>
        </div>
        <div class="row">
            <?php echo $form->labelEx($model,'test_type',array('class'=>'col-md-4 control-label')); ?>
            <div class="col-md-4">
                <?php echo $form->dropdownlist($model, 'test_type', $this->_test_type,
                                                array(  'empty'=>'--Select--',
                                                        'class'=>'form-control',
                                                            'ajax'=>array('type'=>'POST',
                                                                        'url'=>$this->createUrl('MarkDetails/CreateTestView'),
                                                                        'data'=>?,
                                                                        'update'=>'#detail'
                                                                        )
                                                        )
                                                    ); ?>
                <?php echo $form->error($model,'test_type'); ?>
            </div>
        </div>

on selecting test_type i need to send the value of student_track_class_branch as data in test_type via ajax if any one know how to pass this value kindly help me here. 在选择test_type时,如果有人知道如何传递此值,则需要通过ajax将student_track_class_branch的值作为test_type中的数据发送,请在这里帮助我。

You may specify dropdown id manualy and use it or get it with [[CHtml::activeId()]] if it generated by default. 您可以手动指定下拉列表ID并使用它,如果默认生成[[CHtml :: activeId()]],则可以使用它。 So to get another dropdown value you just need this 因此,要获得另一个下拉值,您只需要这个

'data'=> array( 'std_id' => 'js:$("#'.CHtml::activeId($stmodel,'student_track_class_branch').'").val()'
            <?php echo $form->dropdownlist($model, 'test_type', $this->_test_type,
                                            array(  'empty'=>'--Select--',
                                                    'class'=>'form-control',
                                                        'ajax'=>array('type'=>'POST',
                                                                    'url'=>$this->createUrl('MarkDetails/CreateTestView'),
                                                                    'data'=>'js:$("#StudentTracker_student_track_class_branch").val()',
                                                                    'update'=>'#detail'
                                                                    )
                                                    )
                                                ); ?>

Try this one. 试试这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM