title: Remove blank options from select field?
body: <p>I have a fairly simple select field with options fetched from a database (Magento) and echoed via</p>
  
  <pre><code>foreach ($groups as $a){
  
      if($a['label'] != NULL){    
  
          echo "&lt;option value='".$a['value']."'&gt;" . $a['label'] . "&lt;option&gt;";
  
      }
  
  }
  </code></pre>
  
  <p>My problem is that even with server-side code preventing null fields, I still get empty option fields </p>
  
  <p>I also have this JavaScript to sort my options alphabetically, could this cause me to have blank options?</p>
  
  <pre><code>                            function sortlist()
                              {
                                  var cl = document.getElementById('group_id');
                                  var clTexts = new Array();
  
                                  for(i = 2; i &lt; cl.length; i++)
                                  {
                                      clTexts[i-2] =
                                          cl.options[i].text.toUpperCase() + "," +
                                          cl.options[i].text + "," +
                                          cl.options[i].value;
                                  }
  
                                  clTexts.sort();
  
                                  for(i = 2; i &lt; cl.length; i++)
                                  {
                                      var parts = clTexts[i-2].split(',');
  
                                      cl.options[i].text = parts[1];
                                      cl.options[i].value = parts[2];
                                  }
                              }
  
  
                              sortlist();
  </code></pre>
  
  <p>How could one ensure with JavaScript that no <i>blank</i> options in a drop-down select are displayed?</p>
  
  <p>Particulars:</p>
  
  <p>Data source for my foreach contains no blank fields</p>
  
  <p>I get as many blank options as legitimate options</p>
  
  <p>The end result source code looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/Yyjzi.png" alt="enter image description here"></p>