Reputation: 831
I am trying to set up a ajax request when radio button is clicked. Here is my code that I am trying for.
<?php echo $form->dropDownListRow($model, 'page', $pages, array('class' => 'span5', 'prompt' => '-- page --')); ?>
<?php echo $form->radioButtonListInlineRow($model, 'for', array('desktop'=>'Desktop', 'mobile'=>'Mobile'), array('ajax' => array(
'type'=>'POST',
'url'=>Yii::app()->createUrl('/admin/adv/loadpositions'), //or $this->createUrl('loadcities') if '$this' extends CController
'update'=>'#Adv_position', //or 'success' => 'function(data){...handle the data in the way you want...}',
'data'=>array('for'=>'js:this.value', 'page' => 'XXXXXXXX'),
)));
?>
I just want to pass its's value as well as it's upper field's value to the ajax action. How can I make it come true. 'data'=>array('for'=>'js:this.value', 'page' => 'XXXXXXXX'),. Thanks in advance.
Upvotes: 0
Views: 358
Reputation: 1991
Just change your data
attribute to something like this:
'data'=>array('for'=>'js:this.value', 'page' => 'js:$("#someId").val()'),
Upvotes: 1
Reputation: 8726
$(this.form).serialize()
Will give you the form data. Try something like:
<?php
echo $form->radioButtonList($model, 'for', array('desktop'=>'Desktop', 'mobile'=>'Mobile'), array('ajax' => array(
'type'=>'POST',
'url'=>Yii::app()->createUrl('/admin/adv/loadpositions'),
'data'=>array('data'=>'js:$(this.form).serialize()'),
)));
?>
Update:
You can easily parse this serialized string using PHP function parse_str
<?php
$data = 'str1=value1&str2=value2';
parse_str($data);
echo $str1; //value1
echo $str2; //value2
Upvotes: 1