title: JavaScript scope error, variables undefined
body: <p>Please look at this code:</p>
  
  <pre><code>&lt;script&gt;
  var mygrid;
  function lock(){
      for (var i=1; i&lt;15; i++)
      {
          var cur_row=i + "";
              mygrid.lockRow(cur_row,true);
              mygrid.setRowColor(i,"#E5E5E5");
      }
  }
  function doInitGrid(){
  mygrid = new SomeClass;
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body onload="doInitGrid()" dir=rtl&gt;
  &lt;div id="mygrid_container" style="width:905px;height:550px;"&gt;&lt;/div&gt;
  &lt;script&gt;lock();&lt;/script&gt;
    &lt;button onclick="addRow()"&gt;Add Row&lt;/button&gt;  
    &lt;button onclick="removeRow()"&gt;Remove Row&lt;/button&gt;
    &lt;button onclick="lock()"&gt;lock Row&lt;/button&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Why when I run lock function (Without the button), my var is undefined, and when I click on the button everything is ok?</p>