0

JavaScript:

$(function(){
    $('#userID').change(function(){
        $('#username').val($('#userID option:selected').data('username'));
    });
});

HTML:

<select class="form-control" name="nip" id="userID">
    <option value='1' data-username='user_id'>1</option>
    <option value='2' data-username='user_id'>2</option>
    <option value='3' data-username='user_id'>3</option>
</select>
<input type="text" name="name" id="username">

This code works to get selected value from dropdown list into textbox if I selected data first.

My question is, how to show data in textbox before I selected data from dropdown list?

Thanks.

freginold
  • 3,946
  • 3
  • 13
  • 28

1 Answers1

0

No mouse or keyboard events fire for option elements. See the msdn documentation for the events available in options:

http://msdn.microsoft.com/en-us/library/ms535877(VS.85).aspx

In this link you can see another approach to your problem:

Html Select box options on Hover?

Caique Romero
  • 613
  • 8
  • 16