title: jQuery UI Sortable: Updating hidden input value for each item with new position
body: <p>Working with jQuery UI sortable to move around a list of items, and trying to update their positions in form field values.  I can't figure out how to update a hidden input value for each item with its updated position number.  All of the 'currentposition' values should change on each move.  And the position numbers happen to be displayed in <strong>reverse order</strong> on the page.</p>
  
  
  
  <pre class="lang-html prettyprint-override"><code>&lt;div id='sort-list'&gt;
    &lt;div id='listItem_4'&gt;
      ITEM 4
      &lt;input class='originalposition' type='hidden' name='item[4][origposition]' value='4'&gt;
      &lt;input class='currentposition' type='hidden' name='item[4][currposition]' value='4'&gt;
    &lt;/div&gt;
    &lt;div id='listItem_3'&gt;
      ITEM 3
      &lt;input class='originalposition' type='hidden' name='item[3][origposition]' value='3'&gt;
      &lt;input class='currentposition' type='hidden' name='item[3][currposition]' value='3'&gt;
    &lt;/div&gt;
    &lt;div id='listItem_2'&gt;
      ITEM 2
      &lt;input class='originalposition' type='hidden' name='item[2][origposition]' value='2'&gt;
      &lt;input class='currentposition' type='hidden' name='item[2][currposition]' value='2'&gt;
    &lt;/div&gt;
    &lt;div id='listItem_1'&gt;
      ITEM 1
      &lt;input class='originalposition' type='hidden' name='item[1][origposition]' value='1'&gt;
      &lt;input class='currentposition' type='hidden' name='item[1][currposition]' value='1'&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The item[#][currposition] value should be changed to the new updated position number for all items.  The position value for each item should be updated, and have the correct value when the form is submitted.  And the positions will be compared to the orginal values on submission.</p>
  
  <p>The closest I have gotten so far is something like:</p>
  
  <pre class="lang-js prettyprint-override"><code>$(function() {
      $( '#sort-list' ).sortable({
          update : function () { 
              var result = $('#sort-list').sortable('toArray');
              $('input.positioncurrent').each(function() {           
  
              });
          }
      });
  });
  </code></pre>
  
  <p>Thanks for the help.</p>