title: Set set onchange event for dynamically created dropdown using jquery
body: <p>i am creating two dropsdowns like this</p>
  
  <pre><code>var drp_nt = $('&lt;select /&gt;', {
                                 'id'     : 'drp_' + nt,
                                 'name'   : 'drp_' + nt+'[]',
                                 'onchange' : check_data(),
                                 'multiple': true});
  
  var drp_cnt = $('&lt;select /&gt;', {
                                'id'     : 'drp_' + cnt,
                                'name'   : 'drp_' + cnt+'[]',
                                'onchange' : check_data(),
                                'multiple': true});
  </code></pre>
  
  <p>Now i am defining the check_data_function like this</p>
  
  <pre><code>function check_data()
  {
      if($("select option:selected").length==2)
          alert('Two Dropdown Selected');
      else
          alert($("select option:selected").length);
  }
  </code></pre>
  
  <p>but the issue is, the check_data() function isn't getting called.</p>
  
  <p>How can i achieve this..???</p>
  
  <p>Here's my HTML</p>
  
  <pre><code>&lt;div id="cont_drp_nt" class="drp_container"&gt;
  &lt;img id="drp_nt_loader" class="loader_img" src="images/ajax-loader-1.gif" style="display: none;"&gt;
  &lt;select id="drp_nt" name="drp_nt[]" multiple="multiple" style="display: none;"&gt;
  &lt;option value="http://api.hasoffers.com/v3/Affiliate_Offer.json"&gt;http://api.hasoffers.com/v3/Affiliate_Offer.json&lt;/option&gt;
  &lt;/select&gt;
  &lt;div class="btn-group"&gt;
  &lt;button class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" type="button" title="http://api.hasoffers.com/v3/Affiliate_Offer.json"&gt;
  &lt;ul class="multiselect-container dropdown-menu" style="max-height: 200px; overflow-y: auto; overflow-x: hidden;"&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here's the full script</p>
  
  <pre><code>function get_data(v)
  {
      var cnt = 'cnt';
      var ctg = 'ctg';
      var api = 'api';
      var nt = 'nt';
      $('#drp_'+cnt).remove(); 
      $('#drp_'+ctg).remove(); 
      $('#drp_'+api).remove(); 
      $('#drp_'+nt).remove();
      $('.btn-group').remove();
  
  
  
      $('#drp_'+cnt+"_loader").show();
      $('#drp_'+ctg+"_loader").show();
      $('#drp_'+api+"_loader").show();
      $('#drp_'+nt+"_loader").show();
  
      $.post("ajax.php",{'version':v,'func':'get_nt'},
                  function(data)
                  {
                      $('#drp_'+nt+"_loader").hide();
                      var drp_nt = $('&lt;select /&gt;', {
                                       'id'     : 'drp_' + nt,
                                       'name'   : 'drp_' + nt+'[]',
                                       'change' : check_data(),
                                       'multiple': true});
                      for(i=0;i&lt;data.length;i++)
                      {
                              content ="&lt;option value="+data[i].network+"&gt;"+data[i].network+"&lt;/option&gt;";
                              $(drp_nt).append(content);
                      }
                      $('#cont_drp_'+nt).append(drp_nt);
                      $(drp_nt).multiselect({
                                  includeSelectAllOption: true,
                                  enableFiltering: true,
                                  maxHeight: 200,
                                  allSelectedText: 'No option left ...'
                              });
                  }, "json");
  
      $.post("ajax.php",{'version':v,'func':'get_api'},
                  function(data)
                  {
                      $('#drp_'+api+"_loader").hide();
                      var drp_api = $('&lt;select /&gt;', {
                                       'id'     : 'drp_' + api,
                                       'name'   : 'drp_' + api+'[]',
                                       'multiple': true});
                      for(i=0;i&lt;data.length;i++)
                      {
                              content ="&lt;option value="+data[i].api+"&gt;"+data[i].api+"&lt;/option&gt;";
                              $(drp_api).append(content);
                      }
                      $('#cont_drp_'+api).append(drp_api);
                      $(drp_api).multiselect({
                                  includeSelectAllOption: true,
                                  enableFiltering: true,
                                  maxHeight: 200,
                                  allSelectedText: 'No option left ...'
                              });
                  }, "json");
  
  
  
      $.post("ajax.php",{'version':v,'func':'get_category'},
                  function(data)
                  {
                      $('#drp_'+ctg+"_loader").hide();
                      var drp_ctg = $('&lt;select /&gt;', {
                                       'id'     : 'drp_' + ctg,
                                       'name'   : 'drp_' + ctg+'[]',
                                       'multiple': true});
                      for(i=0;i&lt;data.length;i++)
                      {
                              content ="&lt;option value="+data[i].category+"&gt;"+data[i].category+"&lt;/option&gt;";
                              $(drp_ctg).append(content);
                      }
                      $('#cont_drp_'+ctg).append(drp_ctg);
                      $(drp_ctg).multiselect({
                                  includeSelectAllOption: true,
                                  enableFiltering: true,
                                  maxHeight: 200,
                                  allSelectedText: 'No option left ...'
                              });
                  }, "json");
  
  
  
      $.post("ajax.php",{'version':v,'func':'get_country'},
                  function(data)
                  {
                      $('#drp_'+cnt+"_loader").hide();
                      var drp_cnt = $('&lt;select /&gt;', {
                                       'id'     : 'drp_' + cnt,
                                       'name'   : 'drp_' + cnt+'[]',
                                       'multiple': true});
                      for(i=0;i&lt;data.length;i++)
                      {
                              content ="&lt;option value="+data[i].country+"&gt;"+data[i].country+"&lt;/option&gt;";
                              $(drp_cnt).append(content);
                      }
                      $('#cont_drp_'+cnt).append(drp_cnt);
                      $(drp_cnt).multiselect({
                                  includeSelectAllOption: true,
                                  enableFiltering: true,
                                  maxHeight: 200,
                                  allSelectedText: 'No option left ...'
                              });
                  }, "json");
  }
  </code></pre>