Php 试图让Javascript从多个选择框中选择每个子项
我试图使用PHP让Javascript根据特定的get在多个选择框中选择值 这是我的密码:Php 试图让Javascript从多个选择框中选择每个子项,php,javascript,mysql,Php,Javascript,Mysql,我试图使用PHP让Javascript根据特定的get在多个选择框中选择值 这是我的密码: if (isset($_GET["parent"]) && ($_GET['parent'] !== '')) { $parent = $_GET['parent']; echo '<script type=text/javascript> document.getElementById("locpick").value="'.stripsl
if (isset($_GET["parent"]) && ($_GET['parent'] !== '')) {
$parent = $_GET['parent'];
echo '<script type=text/javascript>
document.getElementById("locpick").value="'.stripslashes($parent).'";
</script>';
$reschild = mysql_query("SELECT child_id from loc_child_xref where loc_id='".$locrow['loc_id']."'");
while ($childrow = mysql_fetch_array($reschild)) {
$childloc = mysql_query("SELECT loc_id, loc_desc from location where loc_id='".$childrow['child_id']."'");
while ($childlocrow = mysql_fetch_array($childloc)) {
echo '<script type="text/javascript>
var pl = document.getElementById("child");
for(var i=0; i<pl.options.length;i++) {
if(pl.options[i].value == "' . stripslashes($childlocrow['loc_id']).'") {
pl.options[i].selected = true;
}
}
</script>';
}
}
}
if(isset($\u GET[“parent”])&&($\u GET[“parent”]!=''){
$parent=$_GET['parent'];
回声'
document.getElementById(“locpick”).value=“”.stripslashes($parent)。”;
';
$reschild=mysql_查询(“从loc_child_外部参照中选择child_id,其中loc_id=”””。$locrow['loc_id']。“””);
而($childrow=mysql\u fetch\u数组($reschild)){
$childloc=mysql_query(“从loc_id='”的位置选择loc_id,loc_desc”。$childrow['child_id'].'”);
while($childlocrow=mysql\u fetch\u数组($childloc)){
回声'修复了它。在哪里
loc_id='".$locrow['child_id']."'
等等,应该是
$parent
我很高兴您修复了它,但我同意@DaveRandom。您的代码为结果集中的每个$childlocrow
输出一个新的
。更干净的解决方案是添加selected=“selected”使用PHP到相关的<代码> <代码>。如果不可能的话,你应该考虑<代码>回音< /COD>把ID放进一个JavaScript数组并对它进行检查。这样,你只需要一个“代码> <代码>块。你最好添加一个<代码>选择=“选择”。当您生成HTML时,
属性,而不是向DOM中添加Javascript的随机小部分。修复了它。其中loc_id='“$locrow['child_id']”“等等,应该是$parentHrm,我现在知道这一点很好,并且在将来会记住这一点-我认为我们现在没有足够的开发时间。