我遇到链式(表单元素)选择问题。 我似乎无法使用jquery触发第二个选择选项,使用$ examplevar作为过滤器填充选择,该过滤器是在第一个下拉列表中选择的选项。
<form name="vlan" action="" method="post">
<div class="row">
<div class="col-md-6">
<?php
$con_string= "host=example port=xxxx dbname=example user=example password=example";
$db_con = pg_connect($con_string);
$dev = pg_query($db_con, "SELECT DISTINCT \"Type\" FROM \"End_Devices\"");
echo "
<a class=\"current_page_item\">Location NASID:</a>
<input type=\"text\" name=\"nasid\" />
<br>
<a class=\"current_page_item\">Device Name:</a>
<input type=\"text\" name=\"name\" />
<br>
<input type=\"hidden\" name=\"dvtype\"/>
<a class=\"current_page_item\">Device Type:</a>
<select name=\"slType\" id=\"slType\">";
while ($device = pg_fetch_array($dev))
{
echo "<option id=\"" .$device['Type']. "\">" .$device['Type']. "</option>";
}
echo "<script type=\"text/javascript\">
$(\"#slType\").chained(\"#slModel\");
$(\"#slType\").on(\"change\",function(){
var slTypeID = $(this).val();
$.post('inventoryTEST.php', {slTypeID:slTypeID}, function(data){
$('#slModel').html(data);
});
});
</script>";
echo "
</select>
<br>
<a class=\"current_page_item\">Device Model:</a>
<select name=\"slModel\" id=\"slModel\" >";
if (isset($_POST['slTypeid']))
{
$selection = ($_POST(['slTypeid']));
}
$mod = pg_query($db_con, "SELECT \"Model\" FROM \"End_Devices\" WHERE \"Type\"=\"". $selection . "\"");
while ($model = pg_fetch_array($mod))
{
echo $_POST[type];
echo "<option id=\"" .$model['Model']. "\">" .$model['Model']. "</option>";
}
echo "
</select>
<br>
<a class=\"current_page_item\">Physical Location:</a>
<input type=\"text\" name=\"location\" />
<br>
<a class=\"current_page_item\">Serial:</a>
<input type=\"text\" name=\"serial\" />
<br>
<a class=\"current_page_item\">IP Address:</a>
<input type=\"text\" name=\"ip\" />
<br>
<a class=\"current_page_item\">MAC:</a>
<input type=\"text\" name=\"mac\" />
<br>
<a class=\"current_page_item\">SSID:</a>
<input type=\"text\" name=\"ssid\" />
<br>
<a class=\"current_page_item\">WLAN Area:</a>
<input type=\"text\" name=\"wlan\" />
<br>
<br>
<br>
";
?>
<!--SUBMIT INPUT-->
<input type="submit" value="Save" name="submit" />
</div>
</div>
</form>
有人可以就上面的代码提出建议吗? 我无法触发on change事件来填充用作sql查询的过滤器的var,然后填充第二个链式下拉列表。 谢谢 最好的问候,
答案 0 :(得分:0)
通过使用jquery和.ajax管理来解决它,方法是将所选行内容.change与post一起传递到外部php,然后我使用它作为过滤器查询数据库,同时填充第二个组合框。