0

I am trying to change the name attribute of an input. It is a sales order and has many inputs that collect the qty and item id.

I want the name to index like this item[0] [qty] & item [0] [id]

I was able to get most of it working however it is changing the name for all the inputs to the last one. For example I have 44 items. It is now making the name for all the inputs to be item[43] qty.

Here is part of the code I have written. Thanks for any help you can provide.

var showProduct = function(result) {
var last = $('.display:last');


$(".display ").append("<tr> <td>" + result.id + " </td> <td> " 
                                 + result.brand + " </td> <td>" 
                                 + result.description + "</td> <td>"    
                                  + result.packType + " </td> <td>" 
                                  + result.packSize + " </td> <td>" 
                                  + result.unitsPerPallet + " </td> <td>" 
                                  + result.shippingWeight + " </td> <td>" 
                                  + "<input type = \"number\" class = \"qty\" > </input> 
</td>    </tr>" 
                                 // + "<input type=hidden name = \"id\" value = \"" + result.id
 + "\">"

               );

      last.find('input').val([]);
    last.find('input').attr("name", "lineItem[" + i + "][qty]");         

console.log(i);
i++        

};
Huangism
  • 16,278
  • 7
  • 48
  • 74
pfullen
  • 1
  • 1
  • 1
    Where's `i` coming from? I don't see it anywhere. – Sam Hanley Sep 22 '14 at 17:45
  • without seeing all of the code its hard to give you a "do this and it will work" answer but if i had to guess it seems like it's a closure issue. here's a SO link about closures that might help [How JS Closures Work](http://stackoverflow.com/questions/111102/how-do-javascript-closures-work) – markS Sep 22 '14 at 20:46

0 Answers0