title: Using JavaScript to set the value of a form element
body: <p>I am currently trying to learn JavaScript and in a particular excercise, I am trying to set the value of a button from a user input, but I keep getting an empty value. Where did I go wrong?</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;JavaScript Variables&lt;/title&gt;
          &lt;script type="text/javascript"&gt;
           FIRST_NAME = window.prompt("Enter your first name.");
           document.forms[0].username.value = FIRST_NAME;
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form id="myForm"&gt;
              &lt;input type="button" value="Paul"
                onclick="alert('Paul');"/&gt;
              &lt;br/&gt;&lt;br/&gt;
              &lt;input type="button" value="John"
                onclick="alert('John');"/&gt;
              &lt;br/&gt;&lt;br/&gt;
              &lt;input type="button" value="George"
                onclick="alert('George');"/&gt;
              &lt;br/&gt;&lt;br/&gt;
              &lt;input type="button" value="Ringo"
                onclick="alert('Ringo');"/&gt;
              &lt;br/&gt;&lt;br/&gt;
              &lt;input type="button" id="username" name="username" value=''
                onclick="alert(FIRST_NAME);"/&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The error I get is:</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'username' of undefined</p>
  </blockquote>