title: javascript error: Cannot read property 'options' of null
body: <p>I have a GridView that has a column with a textbox where the user can enter a value and a column with a dropdownlist. If the user enter a values that is not equal to 1 in the textbox, they must select a value from the dropdownlist. The default value in the DDL is "Select" which is just an empty value that was coded in: <code>ddlReasons.Items.Insert(0, new ListItem("Select"));</code>. The DDL is created dynamically but select will always be the default value.   </p>
  
  <pre><code> function UpdateSerialQtyRcvd(SerNoID, QtyRcvd) {
          if (QtyRcvd != 1) {
              var ddl = document.getElementById("ddlReasons");
              var selectedValue = ddl.options[ddl.selectedIndex].value;
              if (selectedValue == "Select") {
                  alert("Must select reason");
              }
  
          }
          else {
              PageMethods.UpdateSerialQtyRcvdUserControl(SerNoID, QtyRcvd, OnUpdateSuccess, OnUpdateFail);
          }
      }
  </code></pre>
  
  <p>If the user enters a value that is not 1 then I need to check what value is in the DDL. If "Select" is the value I need the user to select something else in the DDL but I am getting this error on the line <code>var selectedValue = ddl.options[ddl.selectedIndex].value;</code></p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'options' of null</p>
  </blockquote>
  
  <p>Code for dropdownlist:</p>
  
  <pre><code>&lt;asp:TemplateField HeaderText="Reason"&gt;
   &lt;ItemTemplate&gt;
    &lt;asp:DropDownList ID="ddlReasons" runat="server" class="ReasonDDL" &gt;&lt;/asp:DropDownList&gt;
   &lt;/ItemTemplate&gt; 
  &lt;/asp:TemplateField&gt;
  </code></pre>