input form data resetting (during jquery sortable & html change)

input form data resetting (during jquery sortable & html change)

So right now I am using jquery and jquery ui
I have a sortable list of input data (e.g. single line text input fields)
While I know this isn't a great way to update my index arrays, of position, and some of my form data. It was the first thing I got working after a few hours.
However, my contents of the for loop. Specifically line 5 and 6,  is whats causing me issues.

If i leave them there, everything updates just fine during sortable change. but all my partially entered user form data resets back to default
If i comment out line 5 and 6.  Everything stays in form data, and it is resortable. but i can't update the position[values]


my regex is basically looking for [digit] and replacing it with [newdigit]
I explicitly only use the [] in the places that i need/want updated currently.
  1.  $("#p_scents tbody").sortable({
  2.                 stop: function (event, blob) {
  3.                     var a = $('#p_scents tbody').children();
  4.                     for (var i = 0; i < a.length; i++) {
  5.                         var updated = a.eq(i).html().replace(/\[\d+]/, '[' + i + ']');
  6.                         $(a).eq(i).html(updated);
  7.                     }    
  8.              },});


Any thoughts or suggestions, on what I am doing wrong here? I am fairly new to jquery so I am not sure if there is a simple, clever way to handle this.


additional information, for source html
  1. <table id="p_scents">
            <thead>
  2.                   //blah blah
  3.       </thead>
            <tbody id="p_scents2">
  4.               //a bunch of <tr>  rows which I am sorting,  this part works fine
  5.         </tbody>
  6. </table>

Also the [] is contained in the name of it, so its like
  1. <input class="text-box single-line" name="[' + i + '].QuestionText" type="text" value="" />
for example
...



edit, while I did have id values for them, I think I was modifying them.  and I dont really need too.

I think the id may have been contributing.
but i found a really sloppy work around.
Will investigate further why this is the case

here is my functioning draft
  1. for (var i = 0; i < a.length; i++) {
  2.       $('#p_scents tbody').children().eq(i).find('input').each(function () {
  3.             var temp = this.name;
  4.              temp = temp.replace(/\[\d+]/, '[' + eval(i) + ']');
  5.            this.name = temp;
  6.          });
  7.          $('#p_scents tbody').children().eq(i).find('select').each(function () {
  8.                var temp = this.name;
  9.                temp = temp.replace(/\[\d+]/, '[' + eval(i) + ']');
  10.                 this.name = temp;
  11.            });
  12.            var temp = $('#p_scents tbody').children().eq(i).children().eq(0).html().replace(/\[\d+]/, '[' + eval(i) + ']');
  13.             $('#p_scents tbody').children().eq(i).children().eq(0).html(temp);
  14. }