大家好我有一个非常重要的问题 - 我创建了这个动态页面,允许我添加多个表格或表格供用户填写。它是通过Javascript / AJAX动态完成的。完成后,我会调用一个下拉菜单,并从已指定的标签弹出另一个下拉菜单。但是,当我尝试通过尝试弹出新表来动态执行此操作时 - 我什么都没有显示出来。任何人都可以帮我弄清楚发生了什么事吗?我很......太迷惑了!
我还附上了一张图片以及下面发布的代码。enter image description here
有人可以看到 - 我需要在下拉菜单中显示的框在第一张图片中突出显示为“债务人区域”。第二张图显示了“选择债务国或经济区”的选择菜单如何询问用户“请选择一个地区”。仅当顶部下拉菜单进行选择时,该字段才会出现。 enter image description here
我用来动态调用函数的代码如下:
function showRegions2(str2)
{
if (str2=="")
{
document.getElementById("getregions2").innerHTML="";
return;
}
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 && xmlhttp.status==200)
{
document.getElementById("getregions2").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getregions2.php?k="+str2,true);
xmlhttp.send();
}
This function takes place only during an onchange call. The code for that is as follows:
<table id="debtroeconomiczone" style="width:100%"><tr> <td>
<label>Select Debtor Country or Economic Zone </label></td>
<td><label>
<select id="debtoreconomiczone" name="debtoreconomiczone[]" onchange="showRegions2(this.value)">
<option><?php if(isset($_POST['debtoreconomiczone'])) { echo $_POST['debtoreconomiczone']; } else { echo "-Please Make A Selection-";} ?></option>
<?php
if(!isset($_GET['id2']))
{
$_GET['id2']="";
}
$sql1a = "SELECT * FROM economiczone ORDER BY economiczone asc";
$smt11a = $dbs->prepare($sql1a);
$smt11a -> execute();
while($row1a=$smt11a->fetch(PDO::FETCH_ASSOC))
{
if($row1a['economiczone']==$_GET['id2'] )
echo ("<option selected value='$row1a[economiczone]'>$row1a[economiczone]</option>");
else
echo ("<option value='$row1a[economiczone]'>$row1a[economiczone]</option>");
}
?>
</select></label></td></tr></table>
当我调用javascript函数时 - 这是我使用的代码:
var td2d = document.createElement("td");
td2d.valign = "top";
var slct1 = document.createElement("select");
slct1.id = "debtoreconomiczone";
slct1.name = "debtoreconomiczone[]";
<?php
$sql1a = "SELECT * FROM economiczone ";
$smt1a = $dbs->prepare($sql1a);
$smt1a -> execute();
while($row1a=$smt1a->fetch(PDO::FETCH_ASSOC))
{
echo("var opt=document.createElement(\"option\");\r\n");
echo("opt.value='$row1a[economiczone]';\r\n");
echo("opt.text ='$row1a[economiczone]';\r\n");
echo("slct1.appendChild(opt);");
}
?>
slct1.onchange = "showRegions2(this.value)";
slct1.value='<?php echo $_GET['id2']; ?>';
claims.appendChild(slct1);
td2d.appendChild(slct1);
tr2.appendChild(td2d);
The Debtor Region area that I had highlighted has the following code which returns null - with no drop downs at all!
var td4c = document.createElement("td");
var slct4 = document.createElement("select");
slct4.id = "debtorregion";
slct4.name = "debtorregion[]";
slct4.onchange="showRegions2(this.value)"
<?php
$sql22a = "SELECT * FROM regions JOIN economiczone WHERE economiczone.economiczone = regions.region";
$smt122a = $dbs->prepare($sql22a);
$smt122a -> execute();
while($row1a=$smt122a->fetch(PDO::FETCH_ASSOC))
{
echo("var opt=document.createElement(\"option\");\r\n");
echo("opt.value='$row1a[region]';\r\n");
echo("opt.text ='$row1a[region]';\r\n");
echo("slct4.appendChild(opt);");
}
?>
slct4.value='<?php echo $_GET['id2']; ?>';
claims.appendChild(slct4);
td4c.appendChild(slct4);
tr4.appendChild(td4c);
I tried calling it dynamically through another method and this is the code I used but to no avail:
var td4de = document.createElement("div");
td4de.id = "getregions2";
tr4.appendChild(td4de);
var td4d = document.createElement("td");
var debtorpostalcode = document.createElement("input");
debtorpostalcode.type = "text";
debtorpostalcode.id = "debtorpostalcode";
debtorpostalcode.name = "debtorpostalcode[]";
debtorpostalcode.placeholder = "Debtor Postal/Zip Code";
td4d.appendChild(debtorpostalcode);
tr4.appendChild(td4d);
请告诉我如何通过点击“添加另一个CLaim [+]”选项动态调用代码,如此处所示 -
tinypic。 ?COM / view.php PIC = 2rohwg6&安培; S = 9#.WbbCvMZLfDc