![](/img/trans.png)
[英]I'm trying to auto populate text fields with a calculation of the user input of one field onto another in javascript
[英]auto populate corresponding data into different input fields after selecting a value to one input field javascript
我有一個水平形式,它是使用javascript動態生成的,每個輸入字段都有一個jquery自動完成功能,可以使用$ .get方法填充數據庫中的數據。
當我選擇第一個輸入字段的數據時,我想用相應的值填充第二個輸入字段的數據。 在這里,行被克隆,然后自動完成功能也與行一起被克隆。
在下圖中,如果我選擇類別集,則希望自動填充值字段:
我能夠實現自動完成,但無法實現將數據填充到第二個輸入字段。
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","");
});
}
});
}
您可以在自動完成字段的“選擇/更改”事件上設置其他輸入字段,請參見以下示例:
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">
希望對您有幫助,再見。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.