How to trigger else clause in an onload event?
<p>I have the <code>Comments</code> handle in my Google App Engine app to display the comments. I want to stop the page from loading if the user (defined as "chooser" here) is not in <code>localStorage</code>.</p>

<p>I get the first 2 alerts: <code>"load event"</code> and <code>chooser: "undefined"</code>. Since "chooser" is undefined I expect the else clause to trigger but I don't get the alert in else clause.</p>

<p>Also, the first item in ordered list is displayed but not the rest. So I assume there is an issue with loading of the page. How can I fix this?</p>

<pre><code>class Comments(webapp.RequestHandler):
    def get(self):
        self.response.out.write("""
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Choices&lt;/title&gt;
&lt;script type="text/javascript"&gt;

function showChoices ()

{ 

  alert("load event"); 
  var chooser = localStorage.getItem("chooser"); 
  alert("chooser: " + chooser);

  if (chooser) 
  { 
    document.getElementById("topten").style.display="inline"; 
  }
  else 
  { 
    alert("else triggers"); 
    document.write("get an invitation"); 
  } 
}

  window.onload = showChoices;

      &lt;/script&gt;

  &lt;/head&gt;

  &lt;body&gt;
    &lt;div class="content"&gt;""")

        #python code:
        query = Users.all()
        e = query.fetch(10)
        self.response.out.write("""&lt;ol&gt;""")
        for item in e:
            self.response.out.write("""
            &lt;div id="topten" class="title" style="display:none"&gt;

                &lt;li&gt;%s (&lt;span class="small"&gt;%s&lt;/span&gt;)&lt;/li&gt;

            &lt;/div&gt;
            &lt;hr&gt;&lt;br /&gt;""" 
            % tuple([item.choice, item.owner]))
        self.response.out.write("""&lt;/ol&gt;""")
        self.response.out.write("""
    &lt;/div&gt;

  &lt;/body&gt;
&lt;/html&gt;""")
</code></pre>
