dozabt4329 2016-12-29 08:46
浏览 56
已采纳

如何在ComboBox中获取所选值并将其用于第二个ComboBox查询

Here is my Code.

I have several ComboBoxes. I need to get Value from selected in ComboBox and use value in different query. All data I do select from Oracle.

This is my first ComboBox and I need to use VALUE of this ComboBox's option in query of second ComboBox. I mean second ComboBox depends on first select.

How I can get "Value"? I tried to use onchange="this.form.submit()" but it refreshes the page and loses my select. Maybe is it possible to do it with Ajax...

<tr>
    <div class="form-group" style="background-color:#f9f9f9;border:1px solid #ddd;border-radius:4px;padding:2px;">
    <label>Something:</label><span style="color:#FF0000;">*</span></label>
    
        <select class="form-control" input-sm name="example" required>                                    
                                            
            <OPTION VALUE="">Choose any</OPTION>
                                                
            <OPTION VALUE="first">first_name</OPTION>
            <OPTION VALUE="second">second_name</OPTION>
                                        
            </select>
    </div>
</tr>

</div>
  • 写回答

1条回答 默认 最新

  • donglu7286 2016-12-29 12:54
    关注

    I created new php file and name it "js_post.php". When we chose any option from first ComboBox, javascript sending Value to "js_post.php" and there code is cheking Value and depends on Value selecting option.

    <?php 
    if(isset($_POST["action"]) && $_POST["action"]="get_data" && isset($_POST["muracietnov_id1"]) && $_POST["muracietnov_id1"] !="")
    {
    
        if($_POST["muracietnov_id1"]==1)
        {
            
    //```````````````````````HERE SHould be your connection to DB````````````````
    $select_query= sqlsrv_query($connection,$query);
                                                
    while($result=sqlsrv_fetch_array($select_query)
    {
                                                
    echo '<OPTION VALUE="'.$result['DATAID'].'">'.$result['NAME'].'</OPTION>';
                                            
    }
    
        }
    ?>

    Here is Javascript and HTML that I used.

    $("#muracietnov_id").change(function(){
        var url = 'js_post.php';
        var muracietnov_id=$("#muracietnov_id").val();
        var posting = $.post( url, { 'action': 'get_data','muracietnov_id1': muracietnov_id} );
                        posting.done(function( data ) {
                            //alert(data);
                        $("#muracietnov_id2").html(data);   
                        
            }); 
    });
    <tr>
        <div class="form-group" style="background-color:#f9f9f9;border:1px solid #ddd;border-radius:4px;padding:2px;">
            <label>Müraciət Növü:</label><span style="color:#FF0000;">*</span></label>
                
                <select class="form-control" input-sm name="muracietnov" id="muracietnov_id" required>';                                      
                
                        <OPTION VALUE="">Seçiminizi edin</OPTION>';
                        
                        <OPTION VALUE="1">Su təchizatı</OPTION>';
                        <OPTION VALUE="2">Kanalizasiya</OPTION>';
                        </select>';
                        </div>
    </tr>
                
                
    <tr>
        <div class="form-group" style="background-color:#f9f9f9;border:1px solid #ddd;border-radius:4px;padding:2px;">
            <label>Müraciət Səbəbi:</label><span style="color:#FF0000;">*</span></label>
                <select class="form-control" input-sm id="muracietnov_id2" required>
                </select>
        
        </div>
    </tr>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 STM32——硬件IIC从机通信代码实现
  • ¥15 关于GRSL投稿的疑问
  • ¥15 微生物组数据分析--微生物代谢物
  • ¥30 求一跃动小子保卫主公Java算法实现
  • ¥15 地图软件开发技术答疑(api, 地点获取,外观样式)
  • ¥20 物理远程控制麦克风使用问题
  • ¥15 打印预览会泄漏纸钱包密码吗
  • ¥15 在hololens1上运行unity项目只有空窗口
  • ¥25 TABLEAU PREP无法打开
  • ¥15 百度帐号问题/centos