JQuery Onselect?

JTJohnston picture JTJohnston · Apr 8, 2013 · Viewed 8.6k times · Source

When I type in DPRtelephonenumber I want to repeat it in DPRcallerhometelephonenumber.

This script works as long as I am typing. But if <INPUT id="DPRtelephonenumber"> offers a drop-down from a previously used value, AND I select it, <INPUT id="DPRcallerhometelephonenumber"> does not get set.

So, what do I need more than a keyup? How do I write in an onselect??

<input name="DPRtelephonenumber" id="DPRtelephonenumber" type="text">
<input name="DPRcallerhometelephonenumber" id="DPRcallerhometelephonenumber" type="text">
<script type="text/javascript">
  $(document).ready(function() {
    $('#DPRtelephonenumber').keyup(function() {
      $('#DPRcallerhometelephonenumber').val($(this).val());
    });
  });    
</script>

Answer

spryce picture spryce · Apr 8, 2013

You can use the onchange event for drop down menu's.

$('#mySelect').change(function() {
  // do stuff here;
});