我有一个表格,我可以进行所有工作并提交,除了...用户应该选择部门,然后在4个缺陷字段中填充与部门匹配的缺陷。部门和缺陷4件作品。如果我删除4则3个作品,则删除4&3和2作品,依此类推。我认为它正在丢失listindex,但我迷路了。我也将各种变量更改为在每个Defect中也是唯一的,并且结果相同。我只是脑子僵硬,语法有些我想念的东西。以下是部门1和2的代码。
<strong>Department Name:</strong>
<select name=Department_Nam class="required-entry" id="Department_Nam" onchange="javascript: dynamicdropdown(this.options[this.selectedIndex].value);">
<option value="">Select Department</option>
<?php if ($resultdep->num_rows > 0) {
while($row = mysqli_fetch_assoc($resultdep)) {?>
<option value="<?php echo $row['Department_Nam']; ?>"> <?php echo $row['Department_Nam']; ?></option>
<?php }
} ?>
</select>
</div>
<strong>Defect:</strong><br>
<script>
document.write('<select name="DefectDescrip" id="DefectDescrip"> <option value="">Please select defect</option></select>')
</script>
<noscript>
<select name="DefectDescrip" id="DefectDescrip">
<option value="">Please select defect</option>
</select>
</noscript>
</div>
<script>
var rowFrameworkResultInJs =<?php echo json_encode($rowFrameworkResult);?>;
function dynamicdropdown(listindex)
{
document.getElementById("DefectDescrip").length = 0;
document.getElementById("DefectDescrip").options[0]=new Option("Please select defect","");
if (listindex) {
var lookup = {};
var j = 1;
for (var i = 0, len = rowFrameworkResultInJs.length; i < len; i++) {
if (rowFrameworkResultInJs[i].Reject_Code_Department == listindex) {
document.getElementById("DefectDescrip").options[j]=new Option(rowFrameworkResultInJs[i].Reject_Code_Descrip,rowFrameworkResultInJs[i].Reject_Code_Descrip);
j = j+1;
}
}
}
return true;
}
</script>
<br><strong>Defect 2:</strong><br>
<script>
document.write('<select name="DefectDescrip2" id="DefectDescrip2"><option value="">Please select defect</option></select>')
</script>
<noscript>
<select name="DefectDescrip2" id="DefectDescrip2">
<option value="">Please select defect</option>
</select>
</noscript>
</div>
<script>
var rowFrameworkResultInJs =<?php echo json_encode($rowFrameworkResult);?>;
function dynamicdropdown(listindex)
{
document.getElementById("DefectDescrip2").length = 0;
document.getElementById("DefectDescrip2").options[0]=new Option("Please select defect","");
if (listindex) {
var lookup = {};
var j = 1;
for (var i = 0, len = rowFrameworkResultInJs.length; i < len; i++) {
if (rowFrameworkResultInJs[i].Reject_Code_Department == listindex) {
document.getElementById("DefectDescrip2").options[j]=new Option(rowFrameworkResultInJs[i].Reject_Code_Descrip,rowFrameworkResultInJs[i].Reject_Code_Descrip);
j = j+1;
}
}
}
return true;
}
</script>
最佳答案
固定它。我在Department中调用一个函数,需要添加单个函数调用并更改被调用函数以匹配。哇,头抽筋。
关于javascript - PHP,HTML JS MySQL动态下拉列表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54720886/