I have dynamic field to generate select option & text input.
var i=$('table tr').length;
$(".addmore").on('click',function(){
html = '<tr>';
html += '<td><select name="itemType[]" id="itemType_'+i+'" class="form-control input-sm"><option value="AAA">AAA</option><option value="BBB">BBB</option></select></td>';
.....
.....
html += '</tr>';
$('table').append(html);
i++;
});
$(document).on('focus','.autocomplete_txt',function(){
type = $(this).data('type');
if(type =='itemName' )autoTypeNo=0;
$(this).autocomplete({
source: function( request, response ) {
$.ajax({
url : 'ajax',
dataType: "json",
method: 'post',
data: {
search : request.term,
type : type,
select : $("#itemType_"+i).val()
}
success: function( data ) {}
..
Why the $("#itemType_"+i).val()
return an empty value? I have missing something here?
Because the current select
will have a id
say itemType_7
but the value of i
will be 8
as you are incrementing it after creating the select
.
So the fetch the value of latest select
you have created, you should do
$("#itemType_"+(i-1)).val()
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments