title: ASP.NET Checking for elements using Jquery
body: <p>I have a form which is contains an ajaxtoolkit's tab container and inside of the one of the tab container's tab i have a repeater which is returns result of a seach process. After the search process users will be able to update some data by using some textboxes and dropdownlists. What i want to do is validate these textboxes and ddls by using jquery. If all of them is empty or not selected then i don't want to post the form. Also i should say that i have multiple post processes in this form. Every time i push any button inside of this form the jquery function works. How can i prevent this ? I tried this implementation with jquery bu it does not work. Any help would be appriciated.</p>
  
  <p>HTML:</p>
  
  <pre><code>                        &lt;asp:Repeater ID="searchResultRepeater" runat="server"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;form id="searchResultForm"&gt;&lt;/form&gt;
                                  &lt;table border="1" align="center" style="border-color:#ff9900; width:400px; font-weight:bold; font-family:'Oswald', Arial, sans-serif;"&gt;
                                      &lt;tr align="center"&gt;
                                          &lt;td colspan="3"&gt;
                                              Search Results
                                          &lt;/td&gt;
                                      &lt;/tr&gt;
                                      &lt;tr align="center"&gt;
                                          &lt;td&gt;Category:&lt;/td&gt;
                                          &lt;td colspan="2"&gt;&lt;%#DataBinder.Eval(Container.DataItem,"CategoryName") %&gt;&lt;/td&gt;
                                      &lt;/tr&gt;
                                      &lt;tr align="center"&gt;
                                          &lt;td&gt;Brand:&lt;/td&gt;
                                          &lt;td colspan="2"&gt;&lt;%#DataBinder.Eval(Container.DataItem,"BrandName") %&gt;&lt;/td&gt;
                                      &lt;/tr&gt;
                                      &lt;tr align="center"&gt;
                                          &lt;td&gt;Model:&lt;/td&gt;
                                          &lt;td colspan="2"&gt;&lt;%#DataBinder.Eval(Container.DataItem,"ModelName") %&gt;&lt;/td&gt;
                                      &lt;/tr align="center"&gt;
                                      &lt;tr align="center"&gt;
                                          &lt;td&gt;Primary Color:&lt;/td&gt;
                                          &lt;td colspan="2"&gt;&lt;%#DataBinder.Eval(Container.DataItem,"PrimaryColor") %&gt;&lt;/td&gt;
                                      &lt;/tr&gt;
                                      &lt;tr align="center"&gt;
                                          &lt;td&gt;Secondary Color:&lt;/td&gt;
                                          &lt;td colspan="2"&gt;&lt;%#DataBinder.Eval(Container.DataItem,"SecondaryColor") %&gt;&lt;/td&gt;
                                      &lt;/tr&gt;
                                      &lt;tr align="center"&gt;
                                          &lt;td&gt;Size:&lt;/td&gt;
                                          &lt;td&gt;&lt;%#DataBinder.Eval(Container.DataItem,"Size") %&gt;&lt;/td&gt;
                                          &lt;td&gt;
                                              &lt;asp:DropDownList ID="sizeUpdateDdl" runat="server"&gt;
                                                  &lt;asp:ListItem Value=""&gt;--Select--&lt;/asp:ListItem&gt;
                                                  &lt;asp:ListItem Value="8.5"&gt;8.5&lt;/asp:ListItem&gt;
                                                  &lt;asp:ListItem Value="9"&gt;9&lt;/asp:ListItem&gt;
                                                  &lt;asp:ListItem Value="9.5"&gt;9.5&lt;/asp:ListItem&gt;
                                                  &lt;asp:ListItem Value="10"&gt;10&lt;/asp:ListItem&gt;
                                                  &lt;asp:ListItem Value="10.5"&gt;10.5&lt;/asp:ListItem&gt;
                                                  &lt;asp:ListItem Value="11"&gt;11&lt;/asp:ListItem&gt;
                                                  &lt;asp:ListItem Value="11.5"&gt;11.5&lt;/asp:ListItem&gt;
                                                  &lt;asp:ListItem Value="12"&gt;12&lt;/asp:ListItem&gt;
                                                  &lt;asp:ListItem Value="12.5"&gt;12.5&lt;/asp:ListItem&gt;
                                                  &lt;asp:ListItem Value="13"&gt;13&lt;/asp:ListItem&gt;
                                                  &lt;asp:ListItem Value="13.5"&gt;13.5&lt;/asp:ListItem&gt;
                                                  &lt;asp:ListItem Value="14"&gt;14&lt;/asp:ListItem&gt;
                                                  &lt;asp:ListItem Value="15"&gt;15&lt;/asp:ListItem&gt;
                                              &lt;/asp:DropDownList&gt;
                                          &lt;/td&gt;
                                      &lt;/tr&gt;
                                      &lt;tr align="center"&gt;
                                          &lt;td&gt;Price:&lt;/td&gt;
                                          &lt;td&gt;$&lt;%#DataBinder.Eval(Container.DataItem,"Price") %&gt;&lt;/td&gt;
                                          &lt;td&gt;&lt;asp:TextBox ID="priceUpdateText" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/td&gt;
                                      &lt;/tr&gt;
                                      &lt;tr align="center"&gt;
                                          &lt;td&gt;Quantity:&lt;/td&gt;
                                          &lt;td&gt;&lt;%#DataBinder.Eval(Container.DataItem,"Quantity") %&gt;&lt;/td&gt;
                                          &lt;td&gt;&lt;asp:TextBox ID="quantityUpdateText" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/td&gt;
                                      &lt;/tr&gt;
                                      &lt;tr align="center"&gt;
                                          &lt;td colspan="2"&gt;
                                              &lt;asp:LinkButton ID="deleteLink" PostBackUrl='&lt;%# string.Format("~/AdminPanel.aspx?sid={0}", Eval("ShoeID")) %&gt;' OnClick="delete_Click" runat="server"&gt;DELETE&lt;/asp:LinkButton&gt;
                                          &lt;/td&gt;
                                          &lt;td&gt;
                                              &lt;asp:LinkButton ID="updateLink" PostBackUrl='&lt;%# string.Format("~/AdminPanel.aspx?sid={0}", Eval("ShoeID")) %&gt;' OnClick="update_Click" runat="server"&gt;UPDATE&lt;/asp:LinkButton&gt;
                                          &lt;/td&gt;
                                      &lt;/tr&gt;
                                  &lt;/table&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:Repeater&gt;
  </code></pre>
  
  <p>Jquery script:</p>
  
  <pre><code>$(document).ready(function () {
      $('#form1').submit(function () {
          var size = $('#sizeUpdateDdl').val();
          var color1 = $('#pColorUpdateDdl').val();
          var color2 = $('#sColorUpdateDdl').val();
          var price = $('#priceUpdateText').val();
          var quantity = $('#quantityUpdateText').val();
  
          var values = [];
  
          values.push(size);
          values.push(color1);
          values.push(color2);
          values.push(price);
          values.push(quantity);
  
          var check = 0;
  
          values.forEach(function(entry) {
              if(entry === ""){
                  check = 0;
              }else{
                  check = 1;
              }
          });
  
          if(check === 0){
              alert("Please fill at least one field to update this product !");
              return false;
          }
      });
  });
  </code></pre>