i am dynamically generating a html page using php in which i am generating a dropdown combo which have attributes id and value, on selection of any option i want to get the value and id of selected option using js.
echo "";
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<option id='".$row['Id']."' value='".$row['name']."'>"开发者_运维知识库.$row['name']."</option>";
}
echo "</select>";
above is the code. how can i do this.
<select onchange="var opt = this.options[this.selectedIndex]; alert(opt.id); alert(opt.value);">
...
</select>
精彩评论