dousha4804 2018-05-02 06:26
浏览 152

如何在两个下拉菜单中根据列名显示列值

I have a drop down menu; having column names from database table. Now, I have another dropdown menu.

What I want is; When I select column name from first dropdown menu, It shows the values of that selected column name from database table in second dropdown menu.

I have inserted column names for the first dropdown menu in options tag but i want to retrieve all column values based on selected column name from database table.

Here is my code:

<select name="first">

  <option selected="true" disabled="disabled">Select an Option</option> 
  <option value="all">Select All</option>   
  <option value="a">a</option>
  <option value="b">b</option>
  <option value="c">c</option>
  <option value="d">d</option>
</select>

Where a,b,c,d are the column names. Please help me out.

  • 写回答

1条回答 默认 最新

  • douxie5176 2018-05-02 06:44
    关注

    You can try like this

    HTML:

        <select name="category">
        <option value="0">None</option>
        <option value="1" rel="accessories">Novels</option>
        <option value="2" rel="sports">Scooties</option>
        <option value="3" rel="cars">Bikes</option>
    </select>
    
    
    <select name="items" class="cascade">
        <option value="3" class="accessories">Immortals of meluha/option>
        <option value="8" class="accessories">Half Girlfriend</option>
        <option value="1" class="sports">Active 5G</option>
        <option value="4" class="sports">Active 4G</option>
        <option value="6" class="cars">Royal Enfield</option>
        <option value="2" class="cars">Pulsor</option>
    </select>
    

    JQUERY :

    $(document).ready(function(){
        var $cat = $('select[name=category]'),
            $items = $('select[name=items]');
    
        $cat.change(function(){
            var $this = $(this).find(':selected'),
                rel = $this.attr('rel'),
                $set = $items.find('option.' + rel);
    
            if ($set.size() < 0) {
                $items.hide();
                return;
            }
    
            $items.show().find('option').hide();
    
            $set.show().first().prop('selected', true);
        });
      });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真