We are sending data through Ajax call and getting response as array. we want to loop that array and load into array input field. but data not loading into input.
<input type="hidden" name="loadchild[]" id="loadchild[]" >
this textbox is in loop
$.ajax({
type: "POST",
url: "asign.php",
data: {plan_id: plan_id},
dataType: "json",
success: function (dta)
{
/*
here dta['insert_id'] is single value and
dta['child_ids'] are multiple values and i am getting as [1,2,3,4,5] */
for (var i = 0; i < dta['child_ids'].length; i++)
{
$("#loadchild[" + i + "]").val(dta['child_ids'][i]);
}
}
});
here i am getting as [object Object] when asigning value to textbox
Please let me know how to pass array value one by one into
$("#loadchild["+i+"]")This is not a valid jQuery selector, use.eq(i)insteadloadchild[]$("#loadchild[]").eq(i).val(dta['child_ids'][i]);is this valid..?