Chinnu Kar
Chinnu Kar

Reputation: 11

How to get dynamically created textbox value in jquery or javascript

 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

Answers (3)

Neel
Neel

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

John R
John R

Reputation: 2791

Try like this using starts with selector...

$("input[name^='product_']").each(function() {
       var textVal =  $(this).val();
       alert(textVal);
     });

Upvotes: 1

Siamak Ferdos
Siamak Ferdos

Reputation: 3299

Instead of

$('input[name="product_' + i + '"]').val()

try:

$('body').find('input[name="product_' + i + '"]').val()

Upvotes: 0

Related Questions