2017-05-02 16 views
0

我有一個水平的形式,這是使用javascript動態生成的,每個輸入字段都有一個jquery auto complete,它使用$填充數據庫中的數據。得到方法。自動填充相應的數據到不同的輸入字段後,選擇一個值到一個輸入字段javascript

當我選擇一個數據到第一個輸入字段時,我想用相應的值填充數據到第二個輸入字段。這裏行正在克隆,然後自動完成功能也與行一起克隆。

在下面的圖片,如果我選擇設置,然後我想的類別自動填充值字段:

enter image description here

我能夠實現自動完成的,但沒能實現,以填補數據到第二個輸入字段。

function loadcategorysetvalue(table,tabdata){ 
    var catsetlov=[]; 
    var catvalov=[]; 
$.get("URL",function(response){ 
    catsetlov=response; 
    }).done(function(){ 
     var row =null; 
     var newId=1; 
     for(var i=0;i<catsetlov.length;i++){ 
     newId++;`enter code here` 
     row=insertrow(table(table,tabdata,"categories"); 
     cell=row.cells[0]; 
     cell.children[0].value=catsetlov[i]; 
     setcatvalue(catsetlov[i]); 
     addbtn(row); 
     var id = cell.children[0].getAttribute("id"); 
     var newId=(id+"_"+newId); 
     cell.children[0].setAttribute("id",newId); 
     $('#'+newId).autocomplete({ 
      source:catsetlov, 
      minLength:0 
     }).focus(function(){ 
      $.get("url",function(response){ 
      catsetlov=response; 
     }); 
      $(this).autocomplete("search",""); 
     }); 
     } 
    }); 
    } 

回答

0

你可以設置其他的自動完成場的「選擇/更改」事件的輸入字段,看下面的例子請:

var mySource = [{"label":"Value one","id":"1"},{"label":"Value two","id":"2"},{"label":"Value three","id":"3"}]; 
 

 
$("#txtAutocomplete").autocomplete({ 
 
    source: mySource, 
 
    select: function(event, ui){ 
 
    if(ui.item){ 
 
     $("#hiddenField").val(ui.item.id); 
 
     return ui.item.label; 
 
    } 
 
    else{ 
 
     $("#hiddenField").val(''); 
 
    } 
 
    }, 
 
    change: function(event, ui){ 
 
    if(ui.item){ 
 
     $("#hiddenField").val(ui.item.id); 
 
    } 
 
    else{ 
 
     $("#hiddenField").val(''); 
 
    } 
 
    } 
 
});
<link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" /> 
 
<script src="https://code.jquery.com/jquery-1.11.3.js"></script> 
 
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 
 
<p> 
 
    Start type something like "Val.." 
 
</p> 
 

 
<input type="text" id="txtAutocomplete"> 
 
<input type="text" id="hiddenField" disabled="disabled">

我希望它可以幫助你,再見。

+0

thankQ @alessandro但問題是這兩個字段都有獨立的$ .get調用,它們是兩個不同的數組:( –

+0

像數組a [1,2,3,4,5,6]和數組b [ a,b,c,d,e,f,g] –

+0

您不能在「catsetlov」中添加所需的所有信息嗎? – Alessandro

相關問題