2010-02-17 97 views
0

我使用PHP在我生成具有屬性ID和值的下拉組合動態生成HTML頁面,在任何選項的選擇,我想獲得的價值和id選擇使用js的選項。HTML選擇的使用JS的選項ID的動態retreival

回聲 「」;

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
     echo "<option id='".$row['Id']."' value='".$row['name']."'>".$row['name']."</option>"; 
    } 
    echo "</select>"; 

以上是代碼。我怎樣才能做到這一點。

回答

1
<select onchange="var opt = this.options[this.selectedIndex]; alert(opt.id); alert(opt.value);"> 
     ... 
</select>