title: How to add options to a select menu in jquery mobile using a database and phonegap
body: <p>I'm trying to add options to a selectmenu in jqueryMobile. I read the values that I would like to add from a sqlite database. The reading from the database works (the console log output tells me it has found 16 rows) and the variable that holds the new options gets filled correctly too. But if I would like to add the options to the selectmenu, I get the error "cannot call methods on selectmenu prior to initialization: attempted to call method 'refresh'. I tried to run the selectmenu() method before the refresh but it did not work either. Here is my code:</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;select name="subject" class="subjectDropdown" data-native-menu="false"&gt;
      &lt;option&gt;%tx_subject%&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>    //  Read all subjects from the database
      fillSubjectsDropdown: function(){
          sz.db.container.transaction(function(tx){
              tx.executeSql("SELECT * FROM SUBJECTS ORDER BY sj_name", [], sz.db.selectSubjectsSuccess, sz.db.errorCB);
          }, sz.db.errorCB, sz.db.successCB);
      },
  
  //  Read subjects Callback
      selectSubjectsSuccess: function(tx, results){
          var len = results.rows.length;
          console.log('### szlog: Subjects found: ' + len);
          var subjects = '&lt;option value=""&gt;' + sz.langdata['subject'] + '&lt;/option&gt;';
          for (var i = 0; i &lt; len; i++){
              subjects += '&lt;option value="' + results.rows.item(i).sj_id + '"&gt;' + results.rows.item(i).sj_name + '&lt;/option&gt;';
          }
          $(".subjectDropdown").html(subjects).selectmenu('refresh', true);
      },
  </code></pre>
  
  <p>I have searched and found some articles but none of them could really help me. Any help would be much appreciated.</p>
  
  <p>I use jqueryMobile 1.2.0, jquery 1.8.3 and phonegap 2.3.0</p>
  
  <p>Thanks</p>