title: JavaScript get element by name
body: <p>Consider this function:</p>
  
  <pre><code>function validate()
  {
    var acc = document.getElementsByName('acc').value;
    var pass = document.getElementsByName('pass').value;
  
    alert (acc);
  }
  </code></pre>
  
  <p>And this HTML part:</p>
  
  <pre><code>&lt;table border="0" cellpadding="2" cellspacing="0" valign="top"&gt;
      &lt;tr&gt;
          &lt;td class="td1"&gt;Account&lt;/td&gt;
          &lt;td class="td2"&gt;&lt;input type="text" name="acc" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr class="td1"&gt;
          &lt;td&gt;Password&lt;/td&gt;
          &lt;td class="td2"&gt;&lt;input type="password" name="pass" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;div&gt;&lt;button onClick="validate()" class="cupid-greenx"&gt;Login now&lt;/button&gt;&lt;/div&gt;
  </code></pre>
  
  <p>The alert box is showing, but it shows "undefined".</p>