动态链接选择框 [英] Dynamic chained select box
问题描述
好的,因此我的页面上有2个选择框,第一个选择框的名称为"select",并带有以下硬编码的选项:
Okay, so I have 2 select boxes on my page, the first with the name "select" with the following options hard-coded:
<select name="select" id="Testid">
<option value="Misc">Misc...</option>
<option value="Stunt">Stunt</option>
<option value="deathmatches">Deathmatches</option>
<option value="Car"> Car </option>
<option value="Races">Races </option>
</select>
但是第二个选择框(名为"deleteTp")我想根据第一个选择框的选择填充一个mysql表.每个选项值在我的数据库中都有一个与该值同名的特定表.
The second select box however (named "deleteTp") I want to populate with a mysql table depending on the selection of the first select box. Each option value has a specific table in my database with the same name as the value.
我知道如何用数据库表填充第二个选择框,但是我不确定如何根据用户的选择动态地执行此操作.
I know how to populate the second select box with the database table, however I'm not sure how to do this dynamically depending on the users choice.
请注意,我只知道基本的javascript.
Please note I only know basic javascript.
如果您想知道为什么要尝试这样做,那是因为第二个选择框将发布到外部页面上,以便从填充表中删除行.
And if you're wondering why I am trying to do this, it's because the second selectbox will be posted to an external page to delete the rows from the populated table.
谢谢您的时间.
推荐答案
$.ajax({
type: 'post',
url: "ajax.php."
data: { id:'your id here' } //your id is your select box selected id.
}).done(function() {
});
在php端:
$id = $_REQUEST['id'];
$json = array();
$sql = mysql_query("select * from yourdb where id = $id");
while ($row = mysql_fetch_assoc($sql)) {
$json[] = $row;
}
echo json_encode($json);
ajax ref:http://api.jquery.com/jQuery.ajax/
ajax ref : http://api.jquery.com/jQuery.ajax/
json参考:http://en.wikipedia.org/wiki/JSON
这篇关于动态链接选择框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!