dropDownList onchange submit question?

I was just wondering if anyone knows a way to have a dropDownList auto submit and keep the url search engine friendly?

this is my code… it work but uses ?id=1 instead of /id/1


CHtml::dropDownList('id', $select, $list, array('onchange'=>'this.form.submit()'))

I changed my form to POST and used this method…


CHtml::dropDownList('id', $select, $list, array('submit'=>'controller/action'));

Which works fine and uses jquery… i’d still like to know a way to use GET and submit the form value via friendly url?

I’m using this




<?= CHtml::form(); ?>

        <?= CHtml::dropDownList('id', $select, $list, array('submit' => '')) ?>

<?= CHtml::endForm(); ?>



Yeah that’s what im doing and it works for $_POST method. Is there a way to use dropdown with $_GET and maintain friendly URL’s?

So onchange of dropDownList your url is /controller/action/id/1 instead of /controller/action/?id=1

how to onchange function in dropdownlist

Hi, i am new guy in Yii to, but i think somethings i can share with you:

If you want to give an onchange function in dropdownlist, you can following this code:

CHtml::dropDownList(

        'select_box_name',


        'select_value',


        &#036;data,


        array(


            'onchange' =&gt; 'alert(1)',


        )


    );

where $data is an array of listData

hope can help you :rolleyes:

If you are planning to use onchange and wishes to use $_GET you need to set up you ajax to use method get instead of post.

Have you setup urlManager in config file and in .htaccess to create friendly urls?

By the way, why you want to use SEO friendly URLs, on form submission pages, they will not be indexed by search engine anyway.

@Ivica note that you are posting on an old thread (last response from november 2010)… and in the Yii 1.0.x sub-forum (deprecated)…

Help me mdomba …

i want to post the form onchange, what to do?

Start a new topic in the Yii 1.1 forum, please. :)

got it myfriend,




<?php echo CHtml::dropDownList('id','select_value',$data,array('prompt'=>'Move To Folder','submit'=>array('user/inbox'))

);?>



or




<?php echo CHtml::dropDownList('id','select_value',$data,array('prompt'=>'Move To Folder','submit'=>'user/inbox')

);?>



*where data may CHtml::listData(…)

**user/inbox replace controller/action

Hi Rajith,

I am using a similar thing as u mentioned above. I want to pass some values to the action. How do i do this?




<?php echo CHtml::dropDownList('license_id', 'license', 

              License::items(),

              array(

	              'empty'=>'Select License for this order',

	              'class'=>'span4',

	              'submit'=>array('order/addLicense', 'id'=>$model->orid), // id - will be sent as part of URL

	              'params'=>array('license_id'=>'js: $(this).val()'),      // license_id will be send via POST and its value is selected value of dropDown

	              'csrf'=>true,                                            // CSRF turned on in main config

              ));

?>



Helpfull links:

http://www.yiiframework.com/wiki/48/by-example-chtml/

http://www.yiiframework.com/wiki/24/