title: UncaughtTypeError:Cannot call method 'getElementByTagName' of null
body: <p>I am developing a website in asp.net.
  I used a GridView edited with RadioButton. This is the code for the GridView. Along with this RadioButton GridView is getting value from a table in DataBase and it contains 3 columns.</p>
  
  <pre><code>&lt;asp:GridView ID="creditGridView" runat="server"  Width="500" Height="210px"  GridLines="None" CssClass="classGridView" &gt;
                     &lt;Columns&gt;
                         &lt;asp:TemplateField HeaderText="Pick One"&gt;
                             &lt;ItemTemplate&gt;
                                 &lt;asp:RadioButton ID="radBatId" runat="server" onclick= "javascript:CheckOtherIsCheckedByGVID(this);" /&gt;
                             &lt;/ItemTemplate&gt;
                         &lt;/asp:TemplateField&gt;
                     &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>And I used JavaScript to make the functionality, select one RadioButton at a time in GridView. This is the JavaScript code:</p>
  
  <pre><code>function CheckOtherIsCheckedByGVID(rdBtn) {
          var currentRdBtnId = rdBtn.id;
          alert(currentRdBtnId);
          var parent = document.getElementById("&lt;%=creditGridView.ClientID%&gt;");
  
      var items = parent.getElementsByTagName("input");
      for (i = 0; i &lt; items.length; i++) {
          if (items[i].id != currentRdBtnId &amp;&amp; items[i].type == "radio") {
              if (items[i].checked) {
                  items[i].checked = false;
              }
          }
          else {
              document.getElementById("&lt;%=radioBtnIndex.ClientID%&gt;").value = i;
          }
      }
  }
  </code></pre>
  
  <p>When I put this function in the same page containing the GridView it is working fine. When I put this function in a separate JavaScript file it is showing the error</p>
  
  <blockquote>
    <p>UncaughtTypeError:Cannot call method 'getElementByTagName' of null</p>
  </blockquote>
  
  <p>Here variable parent is getting the value <code>null</code>. i.e. the statement <code>document.getElementById("&lt;%=creditGridView.ClientID%&gt;");</code> is not getting the GridView id when the function is not in the same page. Can anyone help me solve this issue or give me an alternate way to access the GridView id?</p>