title: Jquery validate an Html.BeginForm with steps before submit
body: <p>I have a system which is using Entity Framework 6.1.1, jQuery UI (Combined Library) 1.11.1, jQuery Validation 1.13.0, and ASP.Net MVC 5.1.2 Database First. I'm new to javascript so I'm not exactly sure if I'm going about this the right way.</p>
  
  <p>I have a view which has various various textboxes that need to be filled in on a stepped basis. I want these textboxes validated before the person clicks the "next" button. I have searched around the internet for solutions and I can't seem to find one that matches my requirements. I have everything encased in an Html.BeginForm tag, so I can't reference the id for the form, the textboxes are EditorFor's, and only the last button is the submit button. I have managed to get javascript that checks if all the textboxes are filled in when the page loads, which then disables the "next" button, but then I don't know how to get it to check the textboxes again to enable the "next" button once all of the textboxes have been filled in. Below is the code:</p>
  
  <p>This is my view code:</p>
  
  <pre><code>@using (Html.BeginForm("Create", "Events"))
  </code></pre>
  
  <p>{
      @Html.AntiForgeryToken()</p>
  
  <pre><code>&lt;div class="form-horizontal"&gt;
      &lt;h4&gt;Event&lt;/h4&gt;
      &lt;hr /&gt;
  
      &lt;div class="container"&gt;
          &lt;div class="row form-group"&gt;
              &lt;div class="col-xs-12"&gt;
                  &lt;ul class="nav nav-pills nav-justified thumbnail setup-panel"&gt;
                      &lt;li class="active"&gt;
                          &lt;a href="#step-1"&gt;
                              &lt;h4 class="list-group-item-heading"&gt;Step 1&lt;/h4&gt;
                              &lt;p class="list-group-item-text"&gt;General Details&lt;/p&gt;
                          &lt;/a&gt;
                      &lt;/li&gt;
                      &lt;li class="disabled"&gt;
                          &lt;a href="#step-2"&gt;
                              &lt;h4 class="list-group-item-heading"&gt;Step 2&lt;/h4&gt;
                              &lt;p class="list-group-item-text"&gt;Time and Date Details&lt;/p&gt;
                          &lt;/a&gt;
                      &lt;/li&gt;
                      &lt;li class="disabled"&gt;
                          &lt;a href="#step-3"&gt;
                              &lt;h4 class="list-group-item-heading"&gt;Step 3&lt;/h4&gt;
                              &lt;p class="list-group-item-text"&gt;Questionnaire&lt;/p&gt;
                          &lt;/a&gt;
                      &lt;/li&gt;
                  &lt;/ul&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
  
          &lt;div class="row setup-content " id="step-1"&gt;
              &lt;div class="col-xs-12"&gt;
                  &lt;div class="col-md-12"&gt;
                      &lt;h1 class="text-center"&gt; STEP 1&lt;/h1&gt;
  
                      &lt;div class="form-group" id="eventName" data-toggle="tooltip" data-placement="left" title="Enter an event name"&gt;
                          @Html.LabelFor(model =&gt; model.EventName, htmlAttributes: new { @class = "control-label col-md-2" })
                          &lt;div class="col-md-10"&gt;
                              @Html.EditorFor(model =&gt; model.EventName, new { htmlAttributes = new { @class = "form-control step1" } })
                              @Html.ValidationMessageFor(model =&gt; model.EventName, "", new { @class = "text-danger" })
                          &lt;/div&gt;
                      &lt;/div&gt;
  
                      &lt;div class="form-group" id="eventDesc" data-toggle="tooltip" data-placement="left" title="Enter a description for the event"&gt;
                          @Html.LabelFor(model =&gt; model.EventDescription, htmlAttributes: new { @class = "control-label col-md-2" })
                          &lt;div class="col-md-10"&gt;
                              @Html.TextAreaFor(model =&gt; model.EventDescription, new { htmlAttributes = new { @class = "form-control step1" } })
                              @Html.ValidationMessageFor(model =&gt; model.EventDescription, "", new { @class = "text-danger" })
                          &lt;/div&gt;
                      &lt;/div&gt;
  
                      &lt;div class="form-group" id="eventLocation" data-toggle="tooltip" data-placement="left" title="Enter the event location"&gt;
                          @Html.LabelFor(model =&gt; model.EventLocation, htmlAttributes: new { @class = "control-label col-md-2" })
                          &lt;div class="col-md-10"&gt;
                              @Html.EditorFor(model =&gt; model.EventLocation, new { htmlAttributes = new { @class = "form-control step1" } })
                              @Html.ValidationMessageFor(model =&gt; model.EventLocation, "", new { @class = "text-danger" })
                          &lt;/div&gt;
                      &lt;/div&gt;
  
                      &lt;div class="form-group  eventRating" id="eventRating" data-toggle="tooltip" data-placement="left" title="Rate the event between 1 and 10"&gt;
                          @Html.LabelFor(model =&gt; model.EventRating, htmlAttributes: new { @class = "control-label col-md-2" })
                          &lt;div class="col-md-10"&gt;
                              @Html.EditorFor(model =&gt; model.EventRating, new { htmlAttributes = new { @class = "form-control step1" } })
                              @Html.ValidationMessageFor(model =&gt; model.EventRating, "", new { @class = "text-danger" })
                          &lt;/div&gt;
                      &lt;/div&gt;
  
                      &lt;div class="form-group" id="NoOfEmp" data-toggle="tooltip" data-placement="left" title="Enter the number of employees that can attend this event"&gt;
                          @Html.LabelFor(model =&gt; model.NumberOfEmployees, htmlAttributes: new { @class = "control-label col-md-2" })
                          &lt;div class="col-md-10"&gt;
                              @Html.EditorFor(model =&gt; model.NumberOfEmployees, new { htmlAttributes = new { @class = "form-control step1" } })
                              @Html.ValidationMessageFor(model =&gt; model.NumberOfEmployees, "", new { @class = "text-danger" })
                          &lt;/div&gt;
                      &lt;/div&gt;
  
                      &lt;div class="form-group" id="eventSupplier" data-toggle="tooltip" data-placement="left" title="Enter the name of the event company"&gt;
                          @Html.LabelFor(model =&gt; model.EventSupplier, htmlAttributes: new { @class = "control-label col-md-2" })
                          &lt;div class="col-md-10"&gt;
                              @Html.EditorFor(model =&gt; model.EventSupplier, new { htmlAttributes = new { @class = "form-control step1" } })
                              @Html.ValidationMessageFor(model =&gt; model.EventSupplier, "", new { @class = "text-danger" })
                          &lt;/div&gt;
                      &lt;/div&gt;
  
                      &lt;div class="form-group" id="eventPic" data-toggle="tooltip" data-placement="left" title="Click the Choose Files button to select an event picture"&gt;
                          @Html.LabelFor(model =&gt; model.EventPicture, new { @class = "control-label col-md-2" })
                          &lt;div class="col-md-10"&gt;
                              &lt;div class="btn btn-default btn-file"&gt;
                                  &lt;input id="fileInput" type="file" multiple&gt;
                              &lt;/div&gt;
                              &lt;input type="button" class="btn btn-primary" value="Upload file" onclick="$('#uploader').submit()" /&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
  
                      &lt;div class="text-center"&gt;
                          &lt;button id="activate-step-2" class="btn btn-primary btn-lg "&gt;Next Step&lt;/button&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row setup-content" id="step-2"&gt;
              &lt;div class="col-xs-12"&gt;
                  &lt;div class="col-md-12  text-center"&gt;
                      &lt;h1 class="text-center"&gt; STEP 2&lt;/h1&gt;
  
                      &lt;div class="form-group" id="eventDays" data-toggle="tooltip" data-placement="left" title="Enter the days which teams can go on this event"&gt;
                          @Html.LabelFor(model =&gt; model.EventDays, htmlAttributes: new { @class = "control-label col-md-2" })
  
                          &lt;div class="col-md-10"&gt;
                              @Html.EditorFor(model =&gt; model.EventDays, new { htmlAttributes = new { @class = "form-control" } })
                              @Html.ValidationMessageFor(model =&gt; model.EventDays, "", new { @class = "text-danger" })
                          &lt;/div&gt;
                      &lt;/div&gt;
  
                      &lt;div class="form-group"&gt;
                          @Html.LabelFor(model =&gt; model.EventStart, htmlAttributes: new { @class = "control-label col-md-2" })
                          &lt;div class="col-md-10"&gt;
                              @Html.EditorFor(model =&gt; model.EventStart, new { htmlAttributes = new { @class = "form-control" } })
                              @Html.ValidationMessageFor(model =&gt; model.EventStart, "", new { @class = "text-danger" })
                          &lt;/div&gt;
                      &lt;/div&gt;
  
                      &lt;div class="form-group"&gt;
                          @Html.LabelFor(model =&gt; model.EventEnd, htmlAttributes: new { @class = "control-label col-md-2" })
                          &lt;div class="col-md-10"&gt;
                              @Html.EditorFor(model =&gt; model.EventEnd, new { htmlAttributes = new { @class = "form-control" } })
                              @Html.ValidationMessageFor(model =&gt; model.EventEnd, "", new { @class = "text-danger" })
                          &lt;/div&gt;
                      &lt;/div&gt;
  
                      &lt;div class="form-group" id="eventDuration" data-toggle="tooltip" data-placement="left" title="Enter the number of hours the event can be"&gt;
                          @Html.LabelFor(model =&gt; model.EventDuration, htmlAttributes: new { @class = "control-label col-md-2" })
                          &lt;div class="col-md-10"&gt;
                              @Html.EditorFor(model =&gt; model.EventDuration, new { htmlAttributes = new { @class = "form-control" } })
                              @Html.ValidationMessageFor(model =&gt; model.EventDuration, "", new { @class = "text-danger" })
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;button id="activate-step-3" class="btn btn-primary btn-lg"&gt;Final Step&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row setup-content" id="step-3"&gt;
              &lt;div class="col-xs-12"&gt;
                  &lt;div class="col-md-12  text-center"&gt;
                      &lt;h1 class="text-center"&gt; STEP 3&lt;/h1&gt;
  
                      &lt;div class="form-group"&gt;
                          @Html.LabelFor(model =&gt; model.EventTags, htmlAttributes: new { @class = "control-label col-md-2" })
                          &lt;div class="col-md-10"&gt;
                              @Html.EditorFor(model =&gt; model.EventTags, new { htmlAttributes = new { @class = "form-control" } })
                              @Html.ValidationMessageFor(model =&gt; model.EventTags, "", new { @class = "text-danger" })
                          &lt;/div&gt;
                      &lt;/div&gt;
  
                      &lt;div class="form-group"&gt;
                          @Html.LabelFor(model =&gt; model.EventDuration, htmlAttributes: new { @class = "control-label col-md-2" })
                          &lt;div class="col-md-10 the-basics"&gt;
                              @Html.EditorFor(model =&gt; model.EventDuration, new { htmlAttributes = new { @class = "typeahead form-control", @type = "text", @placeholder = "WHY DOES THIS AND THE ABOVE NOT WORK??" } })
                              @Html.ValidationMessageFor(model =&gt; model.EventDuration, "", new { @class = "text-danger" })
                          &lt;/div&gt;
                      &lt;/div&gt;
  
                      &lt;div class="form-group"&gt;
                          @Html.LabelFor(model =&gt; model.EventDuration, htmlAttributes: new { @class = "control-label col-md-2" })
                          &lt;div class="col-md-10"&gt;
                              &lt;div id="the-basics"&gt;
                                  &lt;input class="typeahead form-control" type="text" placeholder="Tags"&gt;
                                  &lt;input class="typeahead form-control" type="text" placeholder="Tags" data-role="tagsinput"&gt;
                              &lt;/div&gt;
                              @Html.ValidationMessageFor(model =&gt; model.EventDuration, "", new { @class = "text-danger" })
                          &lt;/div&gt;
                      &lt;/div&gt;
  
  
  
                      &lt;button id="final" class="btn btn-primary btn-lg" type="submit" value="Create"&gt;Finish&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>}</p>
  
  <p>As can be seen above, the "next" button is just a button that takes the user to the next step, still in the same view. Also note that there is an "upload" button so I don't know how to validate that part either. The "Finish" button is the submit button that will post all the information.</p>
  
  <hr>
  
  <p>This is my javascript code on the same view:</p>
  
  <pre><code>&lt;script&gt;
      var required_ele = document.getElementsByClassName('form-control step1');
      var allfilled = true;
      for (var i = 0; i &lt; required_ele.length; ++i) {
          var item = required_ele[i];
          if (item.value.length == 0) {
              allfilled = false;
          }
      }
  
      if (allfilled) {
          document.getElementById("activate-step-2").disabled = false;
      }
      else {
          document.getElementById("activate-step-2").disabled = true;
  
      }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>With this javascript code, it checks all the textboxes in step1 on page load and then disables the "Next" button because they're all empty, but it doesn't re-check the textboxes to see if they're filled in.</p>
  
  <hr>
  
  <p>How do I go about doing this, i.e. checking the textboxes to see if they're filled in and disabling the "Next" button until all of them are filled in? Please note the "Upload" button as mentioned above as well. This is the link to an image of the view : <a href="http://pho.to/73TUP" rel="nofollow">MVC View with steps</a></p>
  
  <p>Thanks</p>