title: Cannot read property "First Name" of undefined javascript
body: <p>I have the following basic javascript function that I call when an onClick event occurs</p>
  
  <pre><code>function testMe() {
      var oForm = document.forms["ExampleForm"]["First Name"].value;
      console.log(oForm);
      if (oForm == "") {
          window.alert("This is a test");
      }
      return false;
  }
  </code></pre>
  
  <p>However each time I click on the button, I get the error <code>Cannot read property "First Name" of undefined javascript</code> in the console. The form element <code>First Name</code> exists and does the form name <code>ExampleForm</code></p>
  
  <p>What am I overlooking or doing wrong?</p>
  
  <p><strong>EDIT 0</strong></p>
  
  <p>Although the example I have running at <a href="http://jsfiddle.net/3Ayd8" rel="nofollow">http://jsfiddle.net/3Ayd8</a> works it does not work when I run the same code on a page on an internal website.</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>Here is the output of <code>console.log(document.forms)</code></p>
  
  <pre><code>&lt;form method="post" action="sample.aspx" id="form"&gt;
  
  &lt;script type="text/javascript"&gt;
  //&lt;![CDATA[
  var theForm = document.forms['form'];
  if (!theForm) {
      theForm = document.form;
  }
  function __doPostBack(eventTarget, eventArgument) {
      if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
          theForm.__EVENTTARGET.value = eventTarget;
          theForm.__EVENTARGUMENT.value = eventArgument;
          theForm.submit();
      }
  }
  //]]&gt;
  &lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
      //&lt;![CDATA[
  
  function NewDocument(parentNodeId, classId){ 
      if (parent != window) { 
          parent.NewDocument(parentNodeId, classId); 
      } else { 
          window.top.document.location = '/default.aspx?section=content&amp;action=new&amp;nodeid=' + parentNodeId + '&amp;classid=' + classId; 
      } 
  }
  function NotAllowed(action){ 
      if (parent != window) { 
          parent.NotAllowed('', action); 
      } else { 
          window.top.document.location = '/default.aspx?section=content&amp;action=notallowed&amp;subaction=' + action; 
      } 
  }
  function DeleteDocument(nodeId) { 
      if (parent != window) { 
          parent.DeleteDocument(nodeId); 
      } else { 
          window.top.document.location = '/default.aspx?section=content&amp;action=delete&amp;nodeid=' + nodeId; 
      } 
  }
  function EditDocument(nodeId) { 
      if (parent != window) { 
          parent.EditDocument(nodeId); 
      } else { 
          window.top.document.location = '//default.aspx?section=content&amp;action=edit&amp;nodeid=' + nodeId; 
      } 
  }
  //]]&gt;
  &lt;input type="hidden" name="vmode" id="vmode" value="2"&gt;
  &lt;/div&gt;
  &lt;script src="/GetResource.ashx?scriptfile=%2fCMSScripts%2fcmsedit.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="/ScriptResource.axd?d=aK015nKOf8Jw44OCiklcSydFiWaSIB9l6ZwdCQaMAWlevtaFiOw7Urzac1pIZ9Rs0&amp;amp;t=34d147fd" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="/ScriptResource.axd?d=aK015nKOf8Jw44OCiklcSydFiWaSIB9l6ZwdCQaMAWm_idfkOBcdRXBrkc0cxAR10&amp;amp;t=34d147fd" type="text/javascript"&gt;&lt;/script&gt;
  &lt;div class="aspNetHidden"&gt;
  
      &lt;input type="hidden" name="__SCROLLPOSITIONX" id="__SCROLLPOSITIONX" value="0"&gt;
      &lt;input type="hidden" name="__SCROLLPOSITIONY" id="__SCROLLPOSITIONY" value="0"&gt;
  &lt;/div&gt;
      &lt;div id="manPortal" style="background:none;"&gt;
      &lt;div id="CMSHeaderPad" style="height: 22px; line-height: 0px; "&gt;&lt;/div&gt;&lt;div id="CMSHeaderDiv" style="position: fixed; top: 0px; left: 0px; right: 0px; bottom: auto; z-index: 10000; overflow: hidden; width: 100%; "&gt;
  &lt;script type="text/javascript"&gt;
      //&lt;![CDATA[
  if ( (parent != null) &amp;&amp; (parent.IsCMSDesk) ) { infoElem = document.getElementById('manPortal_pnlPreviewInfo'); if (infoElem) {if ( infoElem.style ) { infoElem.style.display = 'none'; } else { infoElem.display = 'none'; } }}
  //]]&gt;
  &lt;/script&gt;&lt;!-- --&gt;
      &lt;/div&gt;
  &lt;/div&gt;&lt;script type="text/javascript"&gt;
  //&lt;![CDATA[
  Sys.WebForms.PageRequestManager._initialize('manScript', 'form', [], [], [], 90, '');
  //]]&gt;
  &lt;/script&gt;
  
  
  &lt;script type="text/javascript" src="/jquery-1.4.2.min.js"&gt;&lt;/script&gt;
   &lt;script type="text/javascript" src="/jquery-ui-1.8.10.custom.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="/plugins.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="/script.js?v=0.4"&gt;&lt;/script&gt;
  
      &lt;div class="zoneMainContent"&gt;
  &lt;div class="one-col-layout"&gt;
      &lt;div class="col-one"&gt;
      &lt;script type="text/javascript"&gt;
  function testMe() {
      console.log(document.forms);
      console.log(document.getElementById("ExampleForm"));
      return false;
  }
  &lt;/script&gt;
  
      &lt;input id="FirstName" name="FirstName" type="text" value=""&gt; &lt;input name="submit" onclick="return testMe();" type="submit" value="submit"&gt;
  
      &lt;/div&gt;
  &lt;/div&gt;
          &lt;div style="clear:both;line-height:0px;height:0px;"&gt;&lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;&lt;/form&gt;
  </code></pre>