update model with cjuidialog from dropdownlist

Hi,

I’m following the super wiki of Zaccaria http://www.yiiframework.com/wiki/145/cjuidialog-for-create-new-model/ to create a new model using cjuidialog. Great ideas are always simple, no? Thank you Zaccaria!!

I’m trying to follow Russel England’s wiki here to update a model, but from a dropdownlist:

Here is the form:


echo $form->dropDownList($model, 'complainant_id', CHtml::listData(Complainant::model()->findAll($criteria), 'id', 'full_name'),

                array('prompt' => 'Select',

                    'style' => "width: 300px;",

                    'onchange' => '{                    

                    showComplainant._showComplainant_url="'.Yii::app()->createUrl("complainant/ajaxupdate", array("id"=>$model->complainant_id)).'";

                        showComplainant();

                $("#dialogShowComplainant").dialog("open");}'

                )

        );

And this is the javascript function:




<script type="text/javascript">

                // here is the magic

                function showComplainant()

                {

                    // public property                    

                    var _showComplainant_url;

      

                    <?php echo CHtml::ajax(array(

                        'url' => 'js:showComplainant._showComplainant_url',

                        'data' => "js:$(this).serialize()",

                        'type' => 'post',

                        'dataType' => 'json',

                        'success' => "function(data)

                        {

                            if (data.status == 'failure')

                            {

                                $('#dialogShowComplainant div.divComplainantShow').html(data.div);                                

                                // Here is the trick: on submit-> once again this function!

                                $('#dialogShowComplainant div.divComplainantShow form').submit(showComplainant);

                            }

                            else

                            {

                                $('#dialogShowComplainant div.divComplainantShow').html(data.div);

                                setTimeout(\"$('#dialogShowComplainant').dialog('close')\",3000);

                            }

                        }",

                     ));?>;

                    return false;

                }

            </script>



But it does not work.

From Firebug console I can see that ‘$model->complainant_id’ remains empty and the GET ‘id’ with the url has no value.

When I try ‘this.value’ as a parameter to showComplainant(), the selected value gets passed on to the javascript function.

But then, the problem faced by Russel England, as given in his post that led to his wiki article, crops up in my case also.

Can’t figure out why ‘$model->complainant_id’ remains empty at ‘onchange’ event of dropdownlist.

Please help!!