我的问题是,1st DropDown中的每个选项都有自己的表,这会触发第二个DropDown菜单,不知怎的,我无法弄清楚如何调用它。所有教程&我发现的例子中,它们在1st DropDown菜单中触发了一些内容,该菜单位于1表和1之内。第二& 3rd DropDown可以调用另一个表。 (例如:国家,州,市)。
因此,我想知道这是否可行,其中第一个DropDown菜单来自不同的表,第二个DropDown菜单将从第一个DropDown菜单选项中选择填充,第三个DropDown菜单将命令第一个DropDown菜单使用1st DropDown菜单选项。
search.html
.....
<form id="drop_list" name="drop_list" action="searchedasset.php" method="post" >
<fieldset><table><tr>
<thead>
<tr><legend><b>SEARCH ASSET</b></legend></tr>
</thead>
<tbody>
<tr> <!--code for the first list box-->
<td>Search By :</td>
<td><select name="cat_id" onChange="SelectSubCat1();" >
<Option value="">Choose Search By</option>
</SELECT>
</td>
</tr>
<tr>
<td>Limit By :</td>
<td><select id="SubCat1" name="SubCat1">
<Option value="">Choose Limit By</option>
</SELECT>
</td>
</tr>
</tbody>
</tr></table></fieldset>
.....
search.js
function fillSearch(){
// this function is used to fill the category list on load
addOption(document.drop_list.cat_id, "1", "Brand", "");
addOption(document.drop_list.cat_id, "2", "Category", "");
addOption(document.drop_list.cat_id, "3", "Project", "");
}
function SelectSubCat1(){
// ON selection of category this function will work
removeAllOptions(document.drop_list.SubCat1);
//clear all the elements of the second list
addOption(document.drop_list.SubCat1, "", "Choose Limit By", "");
if(document.drop_list.cat_id.value == '1'){
addOption(document.drop_list.SubCat1,"1", "DELL");
addOption(document.drop_list.SubCat1,"2", "ACER");
addOption(document.drop_list.SubCat1,"3", "SONY");
addOption(document.drop_list.SubCat1,"4", "SAMSUNG");
addOption(document.drop_list.SubCat1,"5", "APPLE");
}
if(document.drop_list.cat_id.value == '2'){
addOption(document.drop_list.SubCat1,"='1'", "Notebook");
addOption(document.drop_list.SubCat1,"2", "Desktop");
addOption(document.drop_list.SubCat1,"3", "LCD Projector");
addOption(document.drop_list.SubCat1,"4", "Scanner");
addOption(document.drop_list.SubCat1,"5", "Printer");
}
if(document.drop_list.cat_id.value == '3'){
addOption(document.drop_list.SubCat1,"1", "1st Purchase");
addOption(document.drop_list.SubCat1,"2", "2nd Purchase");
addOption(document.drop_list.SubCat1,"3", "3rd Purchase");
addOption(document.drop_list.SubCat1,"4", "4th Purchase");
addOption(document.drop_list.SubCat1,"5", "5th Purchase");
}
}
//clear all the elements of the second list
function removeAllOptions(selectbox){
var i;
for(i=selectbox.options.length-1;i>=0;i--){
//selectbox.options.remove(i);
selectbox.remove(i);
}
}
//add new options based on the selection of the first drop down box.
function addOption(selectbox, value, text ){
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
请注意,SubCat1应该来自3个不同名称的表,例如:
[cat_id.value == '1', SubCat1 == 'brandid']
[cat_id.value == '2', SubCat1 == 'categoryid']
[cat_id.value == '3', SubCat1 == 'purchaseid']
因此,这可能吗?有什么方法可以做到吗?要相应地更改SubCat1在数据库中的名称?这是为了在下一页显示数据。谢谢。