我正在尝试将选定的下拉值传递给我的链接,这样当我调用我的链接时,其相应的操作应该按照从下拉列表中选择的ID运行。在警报中,值即将到来,但现在我将如何将此值传递给链接的param1 查看
<script type="text/javascript">
var BASE_PATH = "<?php echo Yii::app()->request->baseUrl; ?>";
function changeSelectedVal(val){
var center_id = val;
/* document.getElementById('centerid').val();*/
alert("Selected id = "+center_id);
}
</script>
<div>
<?php
echo CHtml::activeDropDownList($model, 'center_id',
CHtml::listData(Center::model()->findAll(), 'id', 'name'),
array('empty' => '--Select Center--',
'onchange'=>'changeSelectedVal(this.value)',
)); ?>
</div>
<div class="row buttons">
<?php
echo CHtml::link('Generate PDF', array('country/printCenter', 'param1'=>'center_id'));
?>
</div>
答案 0 :(得分:2)
你可以这样做:
<script type="text/javascript">
var BASE_PATH = "<?php echo Yii::app()->request->baseUrl; ?>";
function changeSelectedVal(val){
var url = '<?php echo $this->createUrl("country/printCenter"); ?>¶m1='+ val;
$('#mylink').prop('href',url);
}
</script>
<div>
<?php
echo CHtml::activeDropDownList($model, 'center_id', CHtml::listData(Center::model()->findAll(), 'id', 'name'),
array('empty' => '--Select Center--',
'onchange'=>'changeSelectedVal(this.value)',
)); ?>
</div>
<div class="row buttons">
<?php
echo CHtml::link('Generate PDF', array('country/printCenter', 'param1'=>'center_id'), array('id'=>'mylink'));
?>
</div>