Selection of multiple input fields
<p>I want to select some hidden fields and loop over them. The fields look like:</p>

<pre><code>&lt;form method="post" action="" id="uitjes"&gt;    
    &lt;input type="hidden" value="3" name="form-0-Workshops"&gt;
    &lt;input type="hidden" value="ochtend" name="form-0-Dagdeel"&gt;
    &lt;input type="hidden" value="1" name="form-0-Aantal"&gt;
    &lt;input type="hidden" value="1" name="form-0-Workshops"&gt;
    &lt;input type="hidden" value="middag" name="form-0-Dagdeel"&gt;
    &lt;input type="hidden" value="1" name="form-0-Aantal"&gt;
    &lt;input type="hidden" value="2" name="form-0-Workshops"&gt;
    &lt;input type="hidden" value="middag" name="form-0-Dagdeel"&gt;
    &lt;input type="hidden" value="1" name="form-0-Aantal"&gt;
&lt;/form&gt;
</code></pre>

<p>I select them like this:</p>

<pre><code>var form = $("#uitjes");
form.find('input[name$="Workshops"]').each(rename);
form.find('input[name$="Dagdeel"]').each(rename);
form.find('input[name$="Aantal"]').each(rename);
</code></pre>

<p>The selection of Workshops counts in this case 3 elements:
<code>[input 1, input 1, input 3]</code>.</p>

<p>The problem is that all next elements counts one more element (4):
<code>[input#id_form-0-Dagdeel, input ochtend, input middag, input middag]</code>.</p>

<p>Therefore my loop works not as expected.</p>

<p>The selection of the first element is the preferred behavior. I am not getting why the first selection differs from the next ones. </p>

<p>The reason I am doing is to rename the fields to get an output like this:</p>

<pre><code>&lt;form method="post" action="" id="workshops"&gt;
    &lt;input type="hidden" value="3" name="form-0-Workshops"&gt;
    &lt;input type="hidden" value="ochtend" name="form-0-Dagdeel"&gt;
    &lt;input type="hidden" value="1" name="form-0-Aantal"&gt;
    &lt;input type="hidden" value="1" name="form-1-Workshops"&gt;
    &lt;input type="hidden" value="middag" name="form-1-Dagdeel"&gt;
    &lt;input type="hidden" value="1" name="form-1-Aantal"&gt;
    &lt;input type="hidden" value="2" name="form-2-Workshops"&gt;
    &lt;input type="hidden" value="middag" name="form-2-Dagdeel"&gt;
    &lt;input type="hidden" value="1" name="form-2-Aantal"&gt;
</code></pre>

<p>Therefore I call this function (thanks to @epascarello):</p>

<pre><code>function rename (i) {
    var parts = this.name.split("-");
    parts[1] = i;
    this.name = parts.join("-");
}
</code></pre>
