How to reorder form fields using jquery
<p>I have a PHP page with a form like this:</p>

<pre><code>&lt;form class="form3"&gt;
&lt;label class="form3"&gt;&lt;input type="checkbox"&gt; Item-1&lt;/label&gt;
&lt;label class="form3"&gt;&lt;input type="checkbox"&gt; Item-2&lt;/label&gt;
&lt;label class="form3"&gt;&lt;input type="checkbox"&gt; Item-3&lt;/label&gt;
&lt;label class="form3"&gt;&lt;input type="checkbox"&gt; Item-4&lt;/label&gt;
&lt;label class="form3"&gt;&lt;input type="checkbox"&gt; Item-5&lt;/label&gt;
&lt;/form&gt;
</code></pre>

<p>I have javascript variables set like this:</p>

<pre><code>var checked = ["", "yes", "", "yes", ""];
</code></pre>

<p>Now when the page is loaded, I want to check if the the checked value is "yes" then I want to put those input items first in teh list and the remaining ones later, like this:</p>

<pre><code>&lt;form class="form3"&gt;
&lt;label class="form3"&gt;&lt;input type="checkbox" checked="checked"&gt; Item-2&lt;/label&gt;
&lt;label class="form3"&gt;&lt;input type="checkbox" checked="checked"&gt; Item-4&lt;/label&gt;
&lt;label class="form3"&gt;&lt;input type="checkbox"&gt; Item-1&lt;/label&gt;
&lt;label class="form3"&gt;&lt;input type="checkbox"&gt; Item-3&lt;/label&gt;
&lt;label class="form3"&gt;&lt;input type="checkbox"&gt; Item-5&lt;/label&gt;
&lt;/form&gt;
</code></pre>

<p>I assume, jQuery would be the way to do it.
which means, I will need to loop through the form fields (which I am not sure how) and inside the loop check if the corresponding variable is blank or 'yes', and if yes, print that form field. Then again go through the same loop and print all fields where corresponding variable is blank.</p>

<p>Hope the logic is correct.</p>

<p>I am able to loop through the form elements like this:</p>

<pre><code>$.each($('.form3'),function(i,e){
    if(checked[i] == "")
        {
            e.appendTo($('.form3'));
        }
});
</code></pre>

<p>BUT
obviously, the appendTo line gives me error:</p>

<pre><code>Uncaught TypeError: Object #&lt;HTMLLabelElement&gt; has no method 'appendTo'
</code></pre>

<p>So, now I would need to know how to pick each one of the rows and reorder them while looping.</p>

<p>Thanks</p>
