0
我有2個PHP頁面,htmldisp.php和classfn.php。並且hrmldisp.php中使用的警報不起作用。它實際上應該給一個下拉值。Javascript沒有獲取字段值
htmldisp.php是
<?php include("classfn.php"); $obj=new hello;?>
<script language="javascript">
function submitted(){
var select=document.getElementById('newdrop').value;
alert(select);
}
</script>
<?php
$id="newdrop";
echo $obj->hellofn($id); ?>
<input type="submit" onclick="submitted();"
classfn.php是
<?php
class hello{
function hellofn($id){
$s="select `Name`,`Value` from `Days`;
$q=mysql_query($s);
$p='<td>'.'<select id="$id">';
while($re=mysql_fetch_array($q)){
$value=$re["Value"];
$name=$re["Name"];
$p.='<option value="' . $value . '"' . ($selected==$value ? ' selected="selected"' : '') . '>' . $name . '</option>';
}
$p.='</select>'.'</td>';
return $p;
}
?>
問題是警報(選擇)不工作。謝謝
它不工作?它拋出一個錯誤,顯示'未定義',不射擊? – Igor
它不是因爲它沒有觸發,而是$ js @GrailsGuy沒有獲得$ id =「newdrop」 – look4php