简体   繁体   中英

Yii- How can I make the second dropdownlist values displayed

I'm new to Yii framework and Javascript. Now, I'm using two dropdownlists for min_cost and max_cost. I'm using the below code to list the values in the dropdownlist.

<?php 
$this->widget('ext.combobox.EJuiComboBox', array(
    'model' => $model,
    'attribute' => 'min_cost',
    'data' => Yii::app()->params['cost_min_resales'],
    'options' => array(
        'onSelect' => 'cost_change(item.value);',
        'allowText' => false,
    ),     
    'htmlOptions' => array('placeholder' => 'Min Cost', 'style'=>'width:70px'),
));
?>

</br>

<?php 
$this->widget('ext.combobox.EJuiComboBox', array(
    'model' => $model,
    'attribute' => 'max_cost',
    'data' =>Yii::app()->params['cost_max_resales'],
    'options' => array(                    
        'allowText' => false,
    ),
    'htmlOptions' => array('placeholder' => 'Max Cost', 'style'=>'width:70px'),
));                       
?>

For this I'm using the below script:

<script>
    function cost_change(price) {
        var removed;
        console.log("removed", removed);
        select = "#SearchForm_max_cost_select";
        var value = price;
        console.log("value", value);
        jQuery('#SearchForm_max_cost_select').prepend(removed);
        var toKeep = jQuery('#SearchForm_max_cost_select option').filter(function() {
            return parseInt(this.value) > parseInt(value);
        });

        console.log("to keep",toKeep);
        removed =  jQuery('#SearchForm_max_cost_select option').filter(function() {
            return parseInt(this.value) < parseInt(value);
        });           
    }
</script>  

Now, I want to populate the second dropdownlist with values greater than the value selected in first one. Suppose there are values hardcoded in an array as (1,2,3,4,5) I select 2 from first dropdownlist then all values greater than 2 (ie 3,4,5) should be listed in second dropdownlist.
The above script works fine. I can see the values of second dropdownlist printed in the logs . But, I'm not able to pass this values to second dropdownlist. How can I do this.

Edit : Below is the image of the object I'm getting when I select value . 在此处输入图片说明

this will work, actually i was also facing the same problem but somehow figured it out.

In your controller just check for this condition..

 if ($model->"yourdbid" == null) {
  $model->"yourdbid" = $_POST['yourdbid'];

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM