Pavel Valeriu Pavel Valeriu - 8 months ago 33
HTML Question

How to dynamically check if select field has data

I have a

field that is populated with data after a callback succeeded and I need to call a function when this happens.

I tried to use the jQuery
on .change
but this is fired only after I select another option, not when the select field is populated.

Is there a way to dynamically check if a
field gets some values?

This is what I've done so far:

$('select').on('change', function() {
// Do something

This is how I populate my select list (I'm using google apps script):

function onMetricsSuccess(selectList) {
$.each(selectList, function(key, value) {


You can do this,

Note:I added an ID to apply the event to specific select

// After populating the select list

    $('#myDropdown').on('change', function(){
      alert('Yay I was changed !!');

function populateSelect(){
  var select = $('#myDropdown');
   select.append(new Option('Im a text', 'text'));
   select.append(new Option('Im a number', 'number'));
<script src=""></script>

<select id="myDropdown"></select>