2011-07-14 49 views
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; 
    } 
      ?> 

問題是警報(選擇)不工作。謝謝

+0

它不工作?它拋出一個錯誤,顯示'未定義',不射擊? – Igor

+0

它不是因爲它沒有觸發,而是$ js @GrailsGuy沒有獲得$ id =「newdrop」 – look4php

回答

0

據我可以告訴你,從來沒有呼籲功能submitted。最重要的是,你的HTML格式完全不正確。您的html標記之外有一堆html和javascript。而你有2個開放的html標籤沒有關閉...