[英]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.