Reputation: 11
var max_fields = 9;
var $setting = $("#settingA");
//var $maincontent = $("#mainContent");
// Add html controls
for (var i = 1; i < max_fields; i++) {
var checkedElements = [];
$setting.append("<span style='margin:10px; line-height:2;'><label style='margin-right:10px;'>Channel " + i + "</label><input type='text' name='product_" + i + "' id='product_" + i + "'/></span>");
checkedElements.push($('input[name="product_' + i + '"]').val());
}
Upvotes: 1
Views: 1897
Reputation: 11741
in HTML:-
<input type='text' class='product' name='product_" + i + "' id='product_" + i + "'/>
and in jQuery :-
$('.product').each(function() {
var product = $(this).val();
alert(product);
});
Upvotes: 2
Reputation: 2791
Try like this using starts with selector...
$("input[name^='product_']").each(function() {
var textVal = $(this).val();
alert(textVal);
});
Upvotes: 1
Reputation: 3299
Instead of
$('input[name="product_' + i + '"]').val()
try:
$('body').find('input[name="product_' + i + '"]').val()
Upvotes: 0