Unable to validate both textboxes and dropdown lists for empty check
<p>I have nearly 80 textboxes created dynamically and 10 dropdownlist created dynamically. On the click of additem button i want to make sure that none of these controls are empty.</p>

<p>I am tring the below code</p>

<pre><code> function validateinput() {
      var arrTextBox = document.getElementsByTagName("input");
      var ddlTextBox = document.getElementsByTagName("select");
      var retVal = 1;
      for (i = 0; i &lt; arrTextBox.length; i++) {
          if (arrTextBox[i].type == "text" &amp;&amp; arrTextBox[i].getAttribute("IsMandatory") == "Y" &amp;&amp; arrTextBox[i].value == ""){
              retVal = 0;
          }
      }

      for (j = 0; j &lt; ddlTextBox.length; j++) {

          if (ddlTextBox[j].getAttribute("IsMandatory") == "Y" &amp;&amp; (ddlTextBox[j].value == "" || ddlTextBox[j].selectedIndex == 0)) {
              returnValue = 0;
          }
      }

      if (retVal == 0) {
          alert("Validation Failed");
          return false;
      }
      else {
          alert("Validation Success");
          return true;
      }

  }
</code></pre>

<p>on ascx.cs file </p>

<pre><code> btnAddItem.Attributes.Add("onclick", "{return validateinput()};");
</code></pre>

<p>I get validation failed message if textboxes are empty however, if the dropdown values are null it does not give the validation failed message.
Please let me know where am I going wrong.</p>

<p>Thanks in advance.</p>
