开发者

dynamic retreival of option id of HTML Select's using js

开发者 https://www.devze.com 2022-12-20 04:42 出处:网络
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 op

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消