title: Jquery-Steps : going back stucks with end less loop, if you skipped a step before
body: <p>I am implementing <a href="http://www.jquery-steps.com/Examples#advanced-form" rel="nofollow">jquery-Step Advance Form</a></p>
  
  <p>Here i need to skip a step if age is less than 18, 
  That's a similar example working in above link, 
  when i tried to implement the same , 
  It goes well for skipping a step but once i need to go back on click of previous button, JS use to get stuck with end less loop !!</p>
  
  <p><a href="http://jsfiddle.net/SKVeE/" rel="nofollow">Here</a> i created jsfiddle for the same</p>
  
  <p>Here is JS</p>
  
  <pre><code>$(function () {
  
      $("#form-3").steps({
          bodyTag: "fieldset",
          headerTag: "h1",
          onStepChanging: function (event, currentIndex, newIndex) {
              if (currentIndex &gt; newIndex) {
                  return true;
              }
  
              if (newIndex === 3 &amp;&amp; Number($("#age").val()) &lt; 18) {
                  return false;
              }
  
              var form = $(this);
  
              if (currentIndex &lt; newIndex) {
                  $("#form-3 .body:eq(" + newIndex + ") label.error", form).remove();
                  $("#form-3 .body:eq(" + newIndex + ") .error", form).removeClass("error");
              }
  
              return true;
          },
          onStepChanged: function (event, currentIndex, priorIndex) {
              if (currentIndex === 2 &amp;&amp; Number($("#age").val()) &gt;= 18) {
                  $(this).steps("next");
              }
  
              if (currentIndex === 2 &amp;&amp; priorIndex === 3) {
                  $(this).steps("previous");
              }
          },
          onFinishing: function (event, currentIndex) {
              return true;
          },
          onFinished: function (event, currentIndex) {
              var form = $(this);
              form.submit();
          }
      })
  });
  </code></pre>
  
  <p>here is HTML</p>
  
  <pre><code>&lt;form id="form-3" action="#"&gt;
          &lt;h1 class="noDisplay"&gt;Account&lt;/h1&gt;
          &lt;fieldset&gt;
              &lt;legend&gt;Account Information&lt;/legend&gt;
              &lt;h3&gt; Your Information&lt;/h3&gt;
              &lt;ul&gt;
                  &lt;li&gt;
                      &lt;div&gt;&lt;label for="userName"&gt;User name *&lt;/label&gt;&lt;/div&gt;
                      &lt;div&gt;&lt;input id="userName" name="userName" type="text" class="required" data-msg-required="Username Required!"/&gt;&lt;/div&gt;
                      &lt;div class="cell"&gt;&lt;div class="registerError"&gt;&lt;/div&gt;&lt;/div&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                      &lt;div&gt;&lt;label for="password"&gt;Password *&lt;/label&gt;&lt;/div&gt;
                      &lt;div&gt;&lt;input id="password" name="password" type="text" class="required" data-msg-required="Password Required!"&gt;&lt;/div&gt;
                      &lt;div class="cell"&gt;&lt;div class="registerError"&gt;&lt;/div&gt;&lt;/div&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                      &lt;div&gt;&lt;label for="confirm"&gt;Confirm Password *&lt;/label&gt;&lt;/div&gt;
                      &lt;div&gt;&lt;input id="confirm" name="confirm" type="text" class="required" data-msg-required="Confirm Password Required!"&gt;&lt;/div&gt;
                      &lt;div class="cell"&gt;&lt;div class="registerError"&gt;&lt;/div&gt;&lt;/div&gt;
                  &lt;/li&gt;   
              &lt;/ul&gt;
              &lt;p&gt;(*) Mandatory&lt;/p&gt;
          &lt;/fieldset&gt;
  
          &lt;h1 class="noDisplay"&gt;Profile&lt;/h1&gt;
          &lt;fieldset&gt;
              &lt;legend&gt;Profile Information&lt;/legend&gt;
              &lt;h3&gt; Your Information&lt;/h3&gt;
              &lt;label for="name"&gt;First name *&lt;/label&gt;
              &lt;input id="name" name="name" type="text" class="required"&gt;
              &lt;label for="surname"&gt;Last name *&lt;/label&gt;
              &lt;input id="surname" name="surname" type="text" class="required"&gt;
              &lt;label for="email"&gt;Email *&lt;/label&gt;
              &lt;input id="email" name="email" type="text" class="required email"&gt;
              &lt;label for="address"&gt;Address&lt;/label&gt;
              &lt;input id="address" name="address" type="text"&gt;
              &lt;label for="age"&gt;Age (The warning step will show up if age is less than 18) *&lt;/label&gt;
              &lt;input id="age" name="age" type="text" class="required number"&gt;
              &lt;p&gt;(*) Mandatory&lt;/p&gt;
          &lt;/fieldset&gt;
  
          &lt;h1 class="noDisplay"&gt;Warning&lt;/h1&gt;
          &lt;fieldset&gt;
              &lt;legend&gt;You are to young&lt;/legend&gt;
              &lt;h3&gt; Your Information&lt;/h3&gt;
              &lt;p&gt;Please go away ;-)&lt;/p&gt;
          &lt;/fieldset&gt;
  
          &lt;h1 class="noDisplay"&gt;Finish&lt;/h1&gt;
          &lt;fieldset&gt;
              &lt;legend&gt;Terms and Conditions&lt;/legend&gt;
              &lt;h3&gt; Your Information&lt;/h3&gt;
              &lt;input id="acceptTerms" name="acceptTerms" type="checkbox" class="required"&gt; &lt;label for="acceptTerms"&gt;I agree with the Terms and Conditions.&lt;/label&gt;
          &lt;/fieldset&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>I have observed currentIndex and newIndex parameter are not getting correct values but i don't understand why?</p>