title: document.forms[i] code works in the page but gives "undefined" error in  Greasemonkey
body: <p>So there is a page with about 50 forms.</p>
  
  <p>The first form is a search, so I skip that form.</p>
  
  <p>The remaining 49, I care about.</p>
  
  <p>Out of those 49, I am only looking for forms with the go value equal to renew.</p>
  
  <p>I wrote the code in scratch pad and it works fine.</p>
  
  <p>I paste it into Greasemonkey and I get <code>"document.forms[i].go is undefined"</code></p>
  
  <p>Here is my code:</p>
  
  <pre><code>var i=1 ;
  var total = document.forms.length -1;
  while (i&lt;=total) {
  
      var go_val = document.forms[i].go.value;
      if(go_val == "renew"){
          document.forms[i].setAttribute('target','_blank');
      }
  
      i++;
  }
  </code></pre>
  
  <p>I have also tried this, to check if the go element exists and the form generates no errors, but does not run <code>setattribute</code>.</p>
  
  <pre><code>var i=0 ;
  var total = document.forms.length -1;
  while (i&lt;=total) {
      if(document.forms[i].go){
      var go_val = document.forms[i].go.value;
      if(go_val == "renew"){
          document.forms[i].setAttribute('target','_blank');
      }
      }
      i++;
  }
  </code></pre>
  
  <p>Why does it work in scratch pad, but not in Greasemonkey?</p>