Php 动态检索HTML Select的选项id';s使用js

Php 动态检索HTML Select的选项id';s使用js,php,javascript,Php,Javascript,我正在使用php动态生成一个html页面,其中我正在生成一个具有属性id和值的下拉组合,在选择任何选项时,我希望使用js获取所选选项的值和id 回声“ while($row=mysql\u fetch\u数组($result,mysql\u ASSOC)){ 回显“$row['name']”; } 回声“; 上面是代码。我怎样才能做到这一点。 <select onchange="var opt = this.options[this.selectedIndex]; alert(opt.i

我正在使用php动态生成一个html页面,其中我正在生成一个具有属性id和值的下拉组合,在选择任何选项时,我希望使用js获取所选选项的值和id

回声“

while($row=mysql\u fetch\u数组($result,mysql\u ASSOC)){
回显“$row['name']”;
}
回声“;
上面是代码。我怎样才能做到这一点。


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