我想根据另一个组合框 1 中的选择更改组合框 2 条目。 我想从数据库中检索 combobox2 的条目,我需要在 php 中执行此操作。 为此,我需要将 combobox1 中的选定值作为 php 变量传递给 php。尝试了很多......但还没有得到输出。 这是我的代码
Degree Type<select id="Select3" name="deg">
<option value="UG">UG</option>
<option value="PG">PG</option>
</select>
Department Name<?php
$host="localhost" ;
$mysql_db="db" ;
$mysql_u="root" ;
$mysql_p="" ;
mysql_connect( "$host", "$mysql_u", "$mysql_p");
mysql_select_db( "$mysql_db");
$sel="select Dept_Name from dept_mast where Deg_Type='???' ";
$val=mysql_query($sel);
$selectbox='<select name=\'userst\'>';
while ($row = mysql_fetch_assoc($val)) {
$selectbox.='<option value=\"' . $row['Dept_Name'] . '\">' . $row['Dept_Name'] . '</option>';
}
$selectbox.='</select>';
echo $selectbox;
?>
我如何在 ???
的位置传递 degree 类型组合框中的选定值
帮帮我! 谢谢!
最佳答案
js:
----
function get_fields() {
var cource = $("#cource option:selected").val();
$.ajax({
type: "POST",
url: 'get_fields.php?cource='+cource,
//Specify the datatype of response if necessary
data: $("#form_id").serialize(),
success: function(data){
$("span#column").html(data);
}
});
}
form.html
---------
// Select the cource
<select name="cource" id="cource" onchange="get_fields()">
<option value="Select" >Select</option>
<option value="PG" >PG</option>
<option value="UG" >UG</option>
</select>
<span id="column">
<select name="department" id="department">
<option value="Select" >Select</option>
</select>
</span>
get_fields.php
---------------
<?php
$select = "select * from department where cource_code = '$_REQUEST['cource']' ";
$department = mysql_query($select);
?>
<select name="department" id="department" >
<option value="select">Select</option>
<?php
if($department){
while ($row = mysql_fetch_array($department)) { ?>
<option value="<?php echo $row['code'] ?>"><?php echo strtoupper($row['department_name']) ;?></option>
<?php }
}
?>
</select>
Try this..Now you can filter with out submit using this code...
关于php - 将 html 组合框值传递给同一文件中的 php 而无需提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24444762/