最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Onchange event of Dropdownlist - Stack Overflow

programmeradmin1浏览0评论

I have a dropdown list. I am using onchange event of this dropdown to show some text in a textbox below. Its perfectly fine, but I want to to do something like this:---

If user click on the drop down then the whole list will be populated. right.. Now if he is trying to choose the value from the list using up/down arrow button of the key board I want to fire the event at that time. How can I do this?

Onchange is not working for this purpose.

I have a dropdown list. I am using onchange event of this dropdown to show some text in a textbox below. Its perfectly fine, but I want to to do something like this:---

If user click on the drop down then the whole list will be populated. right.. Now if he is trying to choose the value from the list using up/down arrow button of the key board I want to fire the event at that time. How can I do this?

Onchange is not working for this purpose.

Share Improve this question edited Aug 27, 2022 at 12:58 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Mar 18, 2010 at 10:54 Mohit JainMohit Jain 44k57 gold badges173 silver badges275 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

You can do something like this:

<script type="text/javascript">
   function change(value){
      alert("key pressed "+value)
   }    
</script>

<select name="k" onkeypress="change(this.value)">
    <option value="acb">ABC</option>
    <option value="def">DEF</option>
</select>

You have the onkeydown event. MSDN

In your case, onchange will be raised when the select list loses the focus.

发布评论

评论列表(0)

  1. 暂无评论