我在链接(表单元素)选择时遇到问题。 我似乎无法使用 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>
有人可以对上面的代码提出建议吗? 我无法触发更改事件来填充用作 sql 查询过滤器的 var,然后填充第二个链接下拉列表。 谢谢 谨致问候,
最佳答案
设法通过使用 jquery 和 .ajax 将选定的行内容 .change 与 post 传递到外部 php 来解决它,然后我使用它作为过滤器查询数据库并同时填充第二个组合框。
关于php、mysql、jquery、表单元素链选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23108578/