title: How do I get the value of a textarea?
body: <p>This is a follow up to <a href="https://stackoverflow.com/questions/8114926/can-i-test-xmlhttprequest-in-sdk-with-localhost">my other question</a>. I am asking again because this seems more a javascript question than a Google App Engine question.</p>
  
  <p>I have a form</p>
  
  <pre><code>&lt;form name="choice_form" id="choice_form" method="post" action="/g/choicehandler" onsubmit="writeToStorage()"&gt;
    &lt;textarea name="choice" rows="7" cols="50"&gt;&lt;/textarea&gt;&lt;br /&gt;
    &lt;input type="submit" value="submit your choice"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I want to take the value of this <code>textarea</code> and send it to the app with <code>formData</code>. I tried this</p>
  
  <pre><code>  var choice = document.getElementById("choice_form").value;
  </code></pre>
  
  <p>but I get "undefined" for the value of "choice". What am I doing wrong? </p>
  
  <p>And also, if I understand correctly, the <code>/g/choicehandler</code> is called twice once by the form and once by the XHR. How do I fix that? Below is the handler:</p>
  
  <pre><code>class Choice(webapp.RequestHandler):
      def get(self):
          self.response.out.write("""
  &lt;html&gt;
    &lt;head&gt;
  &lt;script type="text/javascript"&gt;
  
  var count = 0;
  
  function writeToStorage()
  { 
    var user = "user" + count;
    count++;
    localStorage.setItem("chooser", user);
    var choice = document.getElementById("choice_form").value;
  
    var formData = new FormData();
    formData.append("chooser", user);
    formData.append("choice", choice);
  
    var xhr = new XMLHttpRequest();
    xhr.open("POST", "http://localhost:8086/g/choicehandler", true);
    xhr.onreadystatechange = function (aEvt) {
      if (xhr.readyState == 4 &amp;&amp; xhr.status == 200){ 
        console.log("request 200-OK");
      }
      else {
        console.log("connection error");
      }
    };
    xhr.send(formData);  
    //added this per Aaron Dufour's answer
    return 0;
  };
  
  &lt;/script&gt;
  
    &lt;/head&gt;
    &lt;body&gt;
  
  //changed onsubmit like this: onsubmit="return writeToStorage(); as per Aaron Dufour's answer
  &lt;form name="choice_form" id="choice_form" action="/g/choicehandler" method="post" onsubmit="writeToStorage()"&gt;
    &lt;textarea name="choice" rows="7" cols="50"&gt;&lt;/textarea&gt;&lt;br /&gt;
    &lt;input type="submit" value="submit your choice"&gt;
  &lt;/form&gt;
  
    &lt;/body&gt;
  &lt;/html&gt;""")
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>See <a href="https://stackoverflow.com/questions/8116545/how-do-i-get-the-value-of-a-textarea/8116770#8116770">Aaron Dufour's answer</a> for the solution.</p>