2017-07-04 86 views
0

我想獲得文本框中的值和它的工作,但主要問題是當我從選擇框更新供應商current_vendor變量更改其值但在自動完成功能源URL保持舊的current_vendor值是0,而不是新的,我不知道我做錯了或丟失這裏是我的代碼jQuery自動完成未得到更新值

$(document).ready(function(){ 
    var current_vendor = 0;      
$("select[name=txtvendor]").change(function() { 
    var current_vendor = $(this).find("option:selected").val(); 
}); 
$("input#ProdDescription").autocomplete({ 
    source: "includes/modProducts/search-products.php?viewVendor="+current_vendor, 
    minLength: 1, 
    select: function (event, ui) { 
     var item = ui.item; 
      if(item) { 
       $(this).closest('.row').find('.txtchassis').val(item.ChassisNo); 
       $(this).closest('.row').find('.txtdescription').val(item.BikeDescription); 
       $(this).closest('.row').find('.txtprice').val(item.SellingAmount); 

       $(this).closest('.row').find('.txtbikeid').val(item.BikeID); 
       $(this).closest('.row').find('.txtcostprice').val(item.CostPrice); 
       $(this).closest('.row').find('.txtcolorcode').val(item.ColorCode); 
      } 
     } 
}); 
}); 

回答

0

你需要調用AutoComFunction()功能來更新current_vendor變量的值試試這個代碼,它會解決問題

$("select[name=txtvendor]").change(function() { 
vendor_code = this.value; 
$('.selectpicker').selectpicker('refresh'); 
AutoComFunction(); 
}).change();