how to get value of selected datalist

how do get value of datalist by selection of country. can i get value by onchange?

    <datalist id="countrydata" onchange="fun(this);">
     <option value="Afghanistan">Afghanistan</option>
     <option value="Åland Islands">Åland Islands</option>
     <option value="Albania">Albania</option>
     <option value="India">India</option>
   </datalist>
<label for="country">country</label>
<input type="text"
  list="countrydata"
  id="country" name="country"
  size="50"
  autocomplete="off" />
<script>
    function fun(el){
        var x = document.getElementById('countrydata').value;
        alert(x)
    }
 </script>