Chtml::link with JQuery
I have a drop down list
<?php echo CHtml::dropDownList('adj', $adj, $adjudicators, array('id'=>'adjudicator')); ?>
which holds a number of choices.
I want to get the current value of that drop down and use is as a parameter in my link.
array('name'=>'Assign', 'type'=>'raw', 'value'=>'CHtml::ajaxLink(\'Assign\',array(\'pwdApplication/assignApp\'), array(\'type\'=>\'POST\', \'data\'=> array(\'id\'=>$data->id, \'flag\'=>1, \'adj\'=>\'{getAdj()}\',), \'success\'=>"function(result) {$(开发者_运维问答this).html(\'Assigned\'); }",))'),
Here is the javascript function
<script>
function getAdj() {
return $('#adjudicator').val();
}
</script>
The link is a column in a CGridView
. I'm not able to get the proper value.
Thanks for the help.
The link is created in PHP (before your content reaches the browser). The "current value of the dropdown" is something that only has meaning after your content reaches the browser (and the user can select something from the menu). Therefore, the problem as stated cannot be solved at all with PHP.
You need to make the link execute some JavaScript, which would see what the currently selected item is on the spot, create a URL with this information, and navigate to this URL.
Did you check the html output on the id for the select? You may need to use #adj
instead of #adjudicator
in the jQuery function.
You can also add something like: array('onchange'=>'update_function(this);')
to pass the form info to a function.
Simplified solution (removed the escapes so it's easier to read):
CHtml::ajaxLink('Assign', Yii::app()->createUrl('pwdApplication/assignApp'), array('type'=>'POST', 'data'=>array('id'=>$data->id, 'flag'=>1, 'adj'=>js:getAdj())), array('href'=>Yii::app()->createUrl('pwdApplication/assignApp'), 'id'=>$data->id . 'assign')))
精彩评论