简体   繁体   English

获取所选下拉列表的值以与另一个下拉列表进行比较

[英]Get the value of selected dropdown to compare to another dropdown

I have 2 dropdown, the branch dropdown gets app_cn from database. 我有2个下拉列表,分支下拉列表从数据库获取app_cn。 And the sem dropdown gets app_plan_no. sem下拉列表将获得app_plan_no。 But I need to get the value selected in branch dropdown to compare with value selected in sem dropdown. 但是我需要获取在分支下拉列表中选择的值,以与在sem下拉列表中选择的值进行比较。

I saw this code but I don't have any idea how to do this 我看到了这段代码,但我不知道如何执行此操作

   <?php
    $mysqli = new mysqli("localhost", "root", "", "app");
    $result = $mysqli->query("SELECT * FROM app GROUP BY app_cn ORDER BY app_cn");
    echo'<select name="drop_1" id="drop_1">';
     while($row = $result->fetch_assoc())
        {
           echo '<option value="'.$row['app_cn'].'">'.$row['app_cn'].'</option>';
        }
echo'</select>';

if($_GET['func'] == "drop_1" && isset($_GET['func'])) {
   drop_1($_GET['drop_var']); 
}

function drop_1($drop_var)
{
    $mysqli = new mysqli("localhost", "root", "", "app");
    $results = $mysqli->query("SELECT * FROM app WHERE app_cn='$drop_var' GROUP BY app_plan_no ORDER BY app_plan_no");

    echo '<select name="tier_two" id="tier_two">
          <option value=" " disabled="disabled" selected="selected">Choose one</option>';

          while($drop_2 = $results->fetch_assoc())
            {
            if($drop_2['app_plan_no'] != '')
            {
              echo '<option value="'.$drop_2['app_plan_no'].'">'.$drop_2['app_plan_no'].'</option>';
            }
            }

}
echo'</select>';
?>

<script type="text/javascript">
$(document).ready(function() {
    $('#wait_1').hide();
    $('#drop_1').change(function(){
            if( $(this).val() == "ALL") {
            $("#wait_1").hide();
            $("#result_1").hide();
        }else{
      $('#wait_1').show();
      $('#result_1').hide();
      $.get("func.php", {
        func: "drop_1",
        drop_var: $('#drop_1').val()
      }, function(response){
        $('#result_1').fadeOut();
        setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
      });
      }
        return false;
    });
});

function finishAjax(id, response) {
  $('#wait_1').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}
</script>

And this what I want to do WHERE app_cn='$drop_var' 这就是我想在WHERE app_cn='$drop_var'WHERE app_cn='$drop_var'

My table 我的桌子

counter | app_cn   | app_plan_no 

000004  |  comp1   |  1
000172  |  comp1   |  1
000007  |  comp1   |  2
000005  |  comp2   |  1

And this is my select dropdown 这是我的选择下拉菜单

<select name="branch" id="branch" onchange="showCourses()">
<option value="ALL" selected='ALL'>ALL</option>
<?php
$mysqli = new mysqli("localhost", "root", "", "app");
    $result = $mysqli->query("SELECT * FROM app GROUP BY app_cn ORDER BY app_cn");
     while($row = $result->fetch_assoc())
        {
           echo '<option value="'.$row['app_cn'].'">'.$row['app_cn'].'</option>';
        }?>
</select>
<select name="sem" id="sem" onchange="showCourses()">
<?php

$mysqli = new mysqli("localhost", "root", "", "app");
    $result = $mysqli->query("SELECT * FROM app GROUP BY app_plan_no ORDER BY app_plan_no");
     while($row = $result->fetch_assoc())
        {
           echo '<option value="'.$row['app_plan_no'].'">'.$row['app_plan_no'].'</option>';
        }
        ?>
</select>

To get the value of a select statement using jquery use .val() 要使用jquery获取选择语句的值,请使用.val()

To get the value of a select statement when a form is submited using php (serverside) you can find the value of the variable in the $_POST variable where the key is the value of the name attribute for the select statement. 要获取使用php(服务器端)提交表单时select语句的值,可以在$ _POST变量中找到变量的值,其中键是select语句的name属性的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取选定的下拉列表值-PHP - Get selected Dropdown value - PHP 如何获得选定的下拉值? - How to get selected dropdown value? Laravel 5.6:从下拉列表中获取选定的值以在另一个中使用它 - Laravel 5.6: Get selected value from a dropdown to use it in another PHP:获取Dropdown的值并将其传递给另一个下拉列表 - PHP : Get the value of Dropdown and pass it to another dropdown 使用ajax将所选下拉列表的值作为参数传递给另一个下拉列表中的函数 - Use ajax to pass the value of selected dropdown as an argument to a function in another dropdown 根据laravel中的另一个下拉选择值填充下拉列表 - 编辑表单 - Populate dropdown based on another dropdown selected value in laravel - edit form 如何将所选值从下拉列表传递到下一页中的另一个下拉列表 - how to pass selected value from dropdown to another dropdown in next page 将选定的下拉值发送到另一个 PHP 页面 - send selected dropdown value to another PHP page 根据另一个下拉列表中的选定值限制日期 - Restrict date based on the selected value in another dropdown 获取多个下拉列表的值,并使用javascript比较每个下拉列表 - Get value of multiple dropdown list and compare each dropdown using javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM