Mohit Jain
Mohit Jain

Reputation: 43959

Onchange event of Dropdownlist

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.

Upvotes: 2

Views: 13490

Answers (2)

remi bourgarel
remi bourgarel

Reputation: 9389

You have the onkeydown event. MSDN

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

Upvotes: 1

OverLex
OverLex

Reputation: 2521

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>

Upvotes: 4

Related Questions