我有一个如下所示的代码
我的php获取数据库:
$check = $db->prepare("SELECT DISTINCT company FROM inventory ORDER BY company ASC");
$check->execute();
while($row = $check->fetch(PDO::FETCH_ASSOC)){
$companies[] = array("company" => $row['company']);
//$license[$row['company']][] = array ("license" =>$row['license']);
}
$stmt = $db->prepare("SELECT company,license,total_license FROM inventory ORDER BY company ASC");
$stmt->execute();
while($row1 = $stmt->fetch(PDO::FETCH_ASSOC)){
$license[$row1['company']][] = array ("license" =>$row1['license'], "total_license" =>$row1['total_license']);
}
然后是javascript
function loadCompanies(){
var select = document.getElementById("company");
select.onchange = updateLicense;
for(var i = 0; i < companies.length; i++){
select.options[i+1] = new Option(companies[i].company);
}
}
function updateLicense(){
var companySelect = this;
var company = this.value;
var licenseSelect = document.getElementById("license");
licenseSelect.onchange = updateTotal;
//licenseSelect.options.length = 0; //delete all options if any present
for(var i = 0; i < license[company].length; i++){
licenseSelect.options[i+1] = new Option(license[company][i].license);
}
}
function updateTotal(){
alert("Can update");
var licenseNoSelect = this;
var licenseNo = this.value;
var total = document.getElementById("total_license");
total.value = license[company][licenseNo].total_license;
}
我有一个选择下拉列表来选择公司。选择公司后,我希望根据公司名称填写许可证(1家公司可以拥有许多许可证)。然后在选择许可证后,可以自动更新许可证总数。
公司和许可证以及总许可证在1个表格中。
我的total_license的html如下所示:
<div class="input-control text disabled span7">
<input type="text" class="span5" name="total_license" id="total_license" disabled value="10">
</div>
填充公司和许可证不能正常工作,但对于total_license则没有。
现在的问题是,total_license不会更新许可证号码的更改。警报已触发,但值没有变化。
可以帮我吗?怎么了?