title: forms and getElementById
body: <p>I am having issues using getElementById in a form. I have tried several ways with no luck. I basically need the form to verify that both First Name and Last Name fields are filled in, and display a popup box with the names displayed.</p>
  
  <p>Below is the code I have tried. I tried 2 different ways in my javascript and  I am not sure what I am missing.</p>
  
  <pre><code>&lt;form name="form" id="form" method="post" action=""&gt;  
  
      &lt;p class="FirstName"&gt;  
          &lt;label for="FirstName"&gt;First Name:&lt;/label&gt;
      &lt;/p&gt;
      &lt;p&gt;
          &lt;input name="FirstName" type="text" id="FirstName" /&gt;  
      &lt;/p&gt;  
  
      &lt;p class="LastName"&gt;  
          &lt;label for="LastName"&gt;Last Name:&lt;/label&gt;&lt;/p&gt;
          &lt;p&gt;
          &lt;input name="LastName" type="text" id="LastName" /&gt;  
      &lt;/p&gt;
  
      &lt;p class="submit"&gt;  
          &lt;input name="getName" type="button" id="getName" value="Get Name" onClick=”getName();" /&gt;  
      &lt;/p&gt;  
  &lt;/form&gt;
  </code></pre>
  
  
  
  <pre><code>var getName = function () {
      if (document.getElementById("FirstName").value == "" || document.getElementById("LastName").value == "") {
          return ("Please enter a first name and a last name.");
      } else {
          var FullName = document.getElementById("FirstName").value + ' ' + document.getElementById("LastName").value;
          return FullName;
      }
  }
  </code></pre>
  
  <p></p>
  
  <pre><code>function getName() {
      var FullName = document.getElementById('FirstName');
      document.getElementById('LastName');
      if (FullName.value != "") 
          alert(FullName.value)
      else 
          alert("Please enter first and last name")
  }
  </code></pre>