简体   繁体   中英

Yii - How can I get a dropdownlist based on the value of first dropdownlist

I'm new to Yii framework. I have two dropdownlists with their values hardcoded in properties file. The dropdownlists are created using the below code:

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

So now I want to get the hardcoded values in second dropdownlist based on first.

If first dropdownlist has hardcoded values[1,2,3,4] and second dropdownlist has hardcoded values [1,2,3,4]. Suppose I select 2 in first dropdownlist, the second dropdownlist should have values 3 and 4(greater than value selected in first). How can I do this?

This question is not about yii. You sholud use javascript for things like that.

For start check this:

<select id='first'>
    <option value='1'>1</option>
    <option value='2'>2</option>
    <option value='3'>3</option>
    <option value='4'>4</option>
</select>

<select id='second'>
</select>

<script>
$('#first').on('change', function(e){
    var $options =  $(this).find('option');
    $('#second').html('');
    $.each($options, function(i, element){
        if($(element).attr('value')>$('#first').val()){
            $('#second').append($(element).clone());
        }
    })
})
</script>

http://jsfiddle.net/kj5TK/

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