PHP变量不在Javascript的作用域内,如何使其进入作用域?
我试图在HTML中创建一个下拉列表,但我希望它的默认值由PHP变量的值确定。我本想用JavaScript来实现这一点,但最后出现了著名的“uncaughtreferenceerror:$isnotdefined”错误:/PHP变量不在Javascript的作用域内,如何使其进入作用域?,javascript,php,html,Javascript,Php,Html,我试图在HTML中创建一个下拉列表,但我希望它的默认值由PHP变量的值确定。我本想用JavaScript来实现这一点,但最后出现了著名的“uncaughtreferenceerror:$isnotdefined”错误:/ while(list($ArtikelID, $Type) = mysql_fetch_array($result)) { $arid = $ArtikelID; $te = $Type; } PHP: while(list($ArtikelID, $Type) =
while(list($ArtikelID, $Type) = mysql_fetch_array($result))
{
$arid = $ArtikelID;
$te = $Type;
}
PHP:
while(list($ArtikelID, $Type) = mysql_fetch_array($result))
{
$arid = $ArtikelID;
$te = $Type;
}
HTML+JS:
while(list($ArtikelID, $Type) = mysql_fetch_array($result))
{
$arid = $ArtikelID;
$te = $Type;
}
<form name="send" method="post" action="editartticlesdef.php">
articlenumber: </br>
<input readonly="readonly" name="ArticleID" value=<?php echo $arid ?>></br>
Type: </br>
<select name="Type">
<option value="Article">Article</option>
<option value="Code">Code</option>
<option value="News">News</option>
<option value="Project">Project</option>
</select></br>
<script>
document.getElementById("Type").selectedIndex = <?php echo '$te'; ?>;
</script>
</form>
条款编号:
;
我试图将脚本放在页面的其他位置,但没有成功:/。我怀疑变量不在范围内,但我不知道如何将其重新放入:/。它应该是-
while(list($ArtikelID, $Type) = mysql_fetch_array($result))
{
$arid = $ArtikelID;
$te = $Type;
}
<select name="Type" id="Type">
及
while(list($ArtikelID, $Type) = mysql_fetch_array($result))
{
$arid = $ArtikelID;
$te = $Type;
}
document.getElementById(“类型”)。selectedIndex='';
它应该是-
while(list($ArtikelID, $Type) = mysql_fetch_array($result))
{
$arid = $ArtikelID;
$te = $Type;
}
<select name="Type" id="Type">
及
while(list($ArtikelID, $Type) = mysql_fetch_array($result))
{
$arid = $ArtikelID;
$te = $Type;
}
document.getElementById(“类型”)。selectedIndex='';
如果$te
是介于0和3之间的整数,则需要:
while(list($ArtikelID, $Type) = mysql_fetch_array($result))
{
$arid = $ArtikelID;
$te = $Type;
}
while(list($ArtikelID, $Type) = mysql_fetch_array($result))
{
$arid = $ArtikelID;
$te = $Type;
}
文章
代码
新闻
项目
while(list($ArtikelID, $Type) = mysql_fetch_array($result))
{
$arid = $ArtikelID;
$te = $Type;
}
while(list($ArtikelID, $Type) = mysql_fetch_array($result))
{
$arid = $ArtikelID;
$te = $Type;
}
document.getElementById(“类型”)。selectedIndex=“”;
while(list($ArtikelID, $Type) = mysql_fetch_array($result))
{
$arid = $ArtikelID;
$te = $Type;
}
如果
$te
是介于0和3之间的整数,则需要:
while(list($ArtikelID, $Type) = mysql_fetch_array($result))
{
$arid = $ArtikelID;
$te = $Type;
}
while(list($ArtikelID, $Type) = mysql_fetch_array($result))
{
$arid = $ArtikelID;
$te = $Type;
}
文章
代码
新闻
项目
while(list($ArtikelID, $Type) = mysql_fetch_array($result))
{
$arid = $ArtikelID;
$te = $Type;
}
while(list($ArtikelID, $Type) = mysql_fetch_array($result))
{
$arid = $ArtikelID;
$te = $Type;
}
document.getElementById(“类型”)。selectedIndex=“”;
while(list($ArtikelID, $Type) = mysql_fetch_array($result))
{
$arid = $ArtikelID;
$te = $Type;
}
很抱歉没有回答这个问题,但您不应该使用mysql,因为它已弃用且不安全(请参阅)。请使用MySQLi或PDO。很抱歉没有回答这个问题,但您不应该使用mysql,因为它已弃用且不安全(请参阅)。使用MySQLi或PDO。将
替换为'
PHP或JavaScript是否引发错误?此代码生成的JavaScript是什么?将
替换为'
是PHP还是JavaScript引发了错误?这段代码生成的JavaScript是什么?这很有效,但事实证明我也是个白痴。虽然这解决了我得到的错误,但它也告诉我,我试图选择下拉列表的值,而不是变量$te的值。facepalmWell成功了,但事实证明我也是个白痴。虽然这解决了我得到的错误,但它也告诉我,我试图选择下拉列表的值,而不是变量$te的值。掌纹
while(list($ArtikelID, $Type) = mysql_fetch_array($result))
{
$arid = $ArtikelID;
$te = $Type;
}