更改第二个组合框的数据,更改第一个组合框的数据
Change data of second combo box,onchange of the first one
我有 2 个组合 boxes.in 第一个有州名,我有从数据库中检索的数据,第二个必须到该特定州的地区。我需要的是第一个组合框中的数据更改。第二个组合中的数据也应该更改。这是我的代码。
<select name="district" id="district" onchange="showcomplain()">
<?php
$query="SELECT * FROM `rev_district_master`";
$result=mysql_query($query) or die("Selection query of District Master is Error".mysql_error());
$num = mysql_numrows($result);
while($row=mysql_fetch_row($result))
{
?>
<option value="<?php echo $row[1];?>"><?php echo $row[1];?></option>
<?php
}
?>
This is my ajax file:
function stateComboChange(){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}else{
var url="./ajax/list1.php";
xmlHttp.onreadystatechange=stateChanged1 ;
xmlHttp.open("POST",url,true);
xmlHttp.send(null) ;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function stateChanged1()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("stateCombo").innerHTML=xmlHttp.responseText; }
}
通过 ajax 调用状态更改来执行此操作
function changeCombo(){
var statename=document.getElementByid('state_combo_box').value;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 )
{
if(xmlhttp.status==200)
{
var data=JSON.parse(xmlhttp.responseText);
for(var index= 0;index<data.length;index++)
{
var combo=document.getElementById('district');
combo.options[combo.options.length] = new Option(districtname, value);
}
}
}
}
xmlhttp.open("GET","some_php_file_which_echos_data.php",true);
xmlhttp.send(statename);
}
}
抱歉,我不知道您如何命名 DOM 元素,而是替换文件和 id 名称
第二个组合框的数据在哪里?...我没有看到此代码。
您可以使用 AJAX 请求到数据库并在回调时更改 de 数据。
相关文章:
- Telerik rad组合框多列数据绑定
- 组合框是否需要数据存储
- jqueryeasyui使用子数组组合数据
- 根据组合框选择显示特定数据
- 在d3.json中使用d3.csv组合多个csv文件数据输入的最佳方法是什么
- 将字符串与 JSON 对象组合以返回数据
- 表示可用产品的所有组合的数据结构
- JavaScript JSON组合和数据Anylish
- 将数据加载到存储后,Extjs组合框为空
- Rally App SDK 2.0rc1-为什么我的组合框只在第一次点击时忽略数据存储过滤器
- 如何使用Javascript从组合框中获取数据并将其输入到文本框中
- 显示给定输入数字的数据集中字母表的所有可能组合
- 在highcharts组合图中传递Ajax数据
- 更改第二个组合框的数据,更改第一个组合框的数据
- 谷歌组合图中当前数据的平均线
- 合并位置并从 JSON 输出组合数据
- 组合框/下拉框在数据更新后未更新
- 使用数组和对象的组合循环访问数据
- 构建菜单或组合框,数据存储在“动态”数组中
- 如何将多个事件数据组合为一个适合与fullcalendar一起使用的对象或变量