JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.3/themes/base/jquery-ui.css">
<form>
<input type="text" id="addCatalogItem" />
</form>
<form></form>
JavaScript
function updateWeight() {
var z = $("input.count").length;
alert(z);
}
$("#addCatalogItem").autocomplete({
source: ['Somewhere', 'over', 'the'
, 'rainbow', 'lies', 'teachers', 'T-shirt', 'television'],
minLength: 2,
select: function(event, ui) {
var q = ui.item.product_id;
$('#product_id').val(q);
var r = ui.item.value;
$('#product').val(r);
var field = '<label>' + r + '</label><input class=\"count\" type=\"text\" value=\"\" name=\"field[' + q + ']\"/>';
var $item = $("form");
$(field).appendTo($item);
updateWeight();
}
});