Yii Framework Forum: Pass Radio Button Value Onchange - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Pass Radio Button Value Onchange Rate Topic: -----

#1 User is offline   Yii123 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 13-March 13

Posted 18 March 2013 - 01:07 AM

In the List view i added radio button list for filter the result. How pass the radio button value to the controller action onchange? Radio button list code like this
<?php echo CHtml::radioButtonList('type','',array(
                    '1'=>'Personal',
                    '2'=>'Organization'),array('id'=>'type'),array( 'separator' => "<br/>",'style'=>'display:inline')
                );
                ?> 

On change want to pass the value to controller action and refresh the result?
0

#2 User is offline   yiiplayboy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 03-May 12

Posted 18 March 2013 - 01:29 AM

View PostYii123, on 18 March 2013 - 01:07 AM, said:

In the List view i added radio button list for filter the result. How pass the radio button value to the controller action onchange? Radio button list code like this
<?php echo CHtml::radioButtonList('type','',array(
                    '1'=>'Personal',
                    '2'=>'Organization'),array('id'=>'type'),array( 'separator' => "<br/>",'style'=>'display:inline')
                );
                ?> 

On change want to pass the value to controller action and refresh the result?


you pass a value to controller then you are looking for an ajax call...but what exactly is your purpose?
0

#3 User is offline   Yii123 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 13-March 13

Posted 18 March 2013 - 02:14 AM

The list view used as a search result.
Controller
public function actionSearch()
        {
           $key=$_GET['Text'];
            $criteria = new CDbCriteria();
            $criteria->addSearchCondition('username',$key,true,"OR");
            $criteria->select = "`username`,`country`"; 
           $data=new CActiveDataProvider('User',
                   array('criteria'=>$criteria,'pagination'=>array('pageSize'=>5),
            ));
           $this->render('search', array(
           'ModelInstance' => User::model()->findAll($criteria),
           'dataProvider'=>$data,
            ));               
            
        }


search.php
<?php
//THE WIDGET WITH ID AND DYNAMICALLY MADE SORTABLEATTRIBUTES PROPERTY

$this->widget('zii.widgets.CListView', array(
        'id'=>'user-list',
        'dataProvider'=>$dataProvider,
        'itemView'=>'results',
        'template' => '{sorter}{items}{pager}',
));
?>
<?php echo CHtml::radioButtonList('type','',array(
                    '1'=>'Personal',
                    '2'=>'Organization'),array('id'=>'type'),array( 'separator' => "<br/>",'style'=>'display:inline')
                );
                ?> 


result.php
<?php echo $data->username."<br>"; ?>
<?php echo $data->country; ?>


The user model fields are id, name , country, type, The search result shows the name and country. Now want to filter the results based on the radio button onchange (personal/organisation).

Thanks.
0

#4 User is offline   Yii123 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 13-March 13

Posted 18 March 2013 - 05:21 AM

Any solutions...?
0

#5 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 18 March 2013 - 08:38 AM

View PostYii123, on 18 March 2013 - 05:21 AM, said:

Any solutions...?


add this script to reload on change

//view
Yii::app()->clientScript->registerScript('on-change-type','
 $("#type").on("change", function(){
  window.location = "' . Yii::app()->createUrl("controller/action"). '?type=" + $(this).val();
 });
');
//action
$type = $_GET['type'];
//do something to filter




--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users