title: Display Google App Engine datastore value as selected option in HTML select input
body: <p>I have a value stored in Google App Engine datastore, selected from a dropdown select control.</p>
  
  <p>But every time I load the html page, it does not show me the stored datastore value. Instead it shows the original dropdown select with no option selected.</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;select name="items"&gt;
    &lt;option&gt;Select&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>JavaScript:</p>
  
  <pre><code>(function($) {
      $.fn.changeType = function() {
          var data = [{"user":"a","name":"Mr A"},
                      {"user":"b","name":"Miss B"},
                      {"user":"c","name":"Mrs C"}];
          var tlist = '&lt;option&gt;Select&lt;\/option&gt;';
          $.each(data, function(i,d){
              tlist += '&lt;option value="' + d.user + '"&gt;' + d.name + '&lt;\/option&gt;';
          });
          $("select", this).html(tlist);
      };
  })(jQuery);
  </code></pre>
  
  <p>main.py:</p>
  
  <pre><code># assume model s
  user = db.StringProperty()
  ...
  updated_user = self.request.get('items')
  s.user = updated_user
  s.put()
  </code></pre>
  
  <p>Note that I only store the user (value) part (eg a) in the datastore, but I would like to have the name part (eg Mr A). Is this possible?</p>
  
  <p>Many thanks!</p>
  
  <p>Update:
  Sorry for not being clear. I was using jinja2 with a template value p which draws from the model s</p>
  
  <pre><code>&lt;select name="items"&gt;
      &lt;option&gt;{{ p.user }}&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>and also tried putting this in the jQuery:</p>
  
  <pre><code>var tlist = '&lt;option&gt;{{ p.user }}&lt;\/option&gt;';
  </code></pre>
  
  <p>but there was no effect (well it sort of shows the user (value) part for a split second). Essentially I would like to ask what and where do I put the Google App Engine datastore value in my HTML and jQuery. Thanks.</p>
  
  <p>Update 2:
  I changed the JavaScript to</p>
  
  <pre><code>(function($) {
      $.fn.changeType = function() {
          var data = [{"user":"a","name":"Mr A"},
                      {"user":"b","name":"Miss B"},
                      {"user":"c","name":"Mrs C"}];
          var tselected = $("select option:selected").val();
          var tlist = '&lt;option&gt;Select&lt;\/option&gt;';
          $.each(data, function(i,d){
      if (d.user === tselected)
                  tlist += '&lt;option value="' + d.user + 'selected="selected"&gt;' + d.name + '&lt;\/option&gt;';
              else
                  tlist += '&lt;option value="' + d.user + '"&gt;' + d.name + '&lt;\/option&gt;';
          });
          $("select", this).html(tlist);
      };
  })(jQuery);
  </code></pre>
  
  <p>but tselected does not appear to return the current selected value. Any ideas? Thanks.</p>