activeRadioButtonList - call action on change

Hello!

I’m new to Yii and I’m trying to build a form with radio buttons. on change it should update a model.

A user has a status that should be changed as soon as a radio button is clicked

This is my code:




echo CHtml::beginForm(); 

        

echo CHtml::activeRadioButtonList($model, 'status', Lookup::items('Status'), 

        array( 'onclick'=> 'this.form.submit()'));

echo CHtml::endForm();



How can I specify which action should be called? How can I do this with ajax in order to update a list on the same site?

Thank you!


//you can do it by setting the form action before submit the form.Try with below coding


echo CHtml::activeRadioButtonList($model, 'status', Lookup::items('Status'), 

array( 'onclick'=> 'javascript:this.form.action=\'index.php?r=controller\action\';this.form.submit()'));




It works! Thank you very much!!!

Is this also possible with ajax? With the above method I have to redirect back to the page from the action.

Yes, you just need to change the onClick event to something like:




js:function(){

  var myformdata = $('#my_form_id').serialize();


  $.ajax('/controller/action',{

    data:myformdata,

    success:function(msg){

      alert(msg);

    }

  });

}



Thank you very much!

I was able to implement it :)

Great community!!!