我想将我的输入文本链接到另一个输入文本,但它的计划就像在数据库中一样,
例如:我想在第一个输入框(名称项)中输入“Acesulfame”,然后在第二个输入框中输入“Sweeteners”(Sub.Sategory),在第三个输入框中输入“0001” “(代码Oracle)。
那我该怎么做?,这只是一个例子。
<div class="form-group">
<label class="control-label col-sm-3" for="code_oracle">Code Oracle</label>
<div class="col-sm-9">
<input name='code_oracle' type='text' class='form-control' placeholder='Code Oracle' required title='Code Revision Formula' id="code_oracle" value=""></input>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="name_item">Name Item</label>
<div class="col-sm-9">
<input name='name_item' type='text' class='form-control' placeholder='Nama Sample' required title='Name Sample' id="name_item" value=""></input>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="category">Sub. Category</label>
<div class="col-sm-9">
<input name='category' type='text' class='form-control' placeholder='Sub. Category' required title='Sub. Category' id="category" value=""></input>
</div>
</div>
我的真实代码在下面。
<input name='kode_oracle' type='text' class='form-control' placeholder='Kode Oracle' required data-toggle='tooltip' data-placement='left' title='Kode Revisi Formula' id='kode_oracle'>
<input name='nama_item' type='text' class='form-control' placeholder='Nama Sederhana' required data-toggle='tooltip' data-placement='left' title='Nama Sederhana' id='nama_item' onkeyup='fill()'>
<input name='sub_kategori' type='text' class='form-control' placeholder='Sub. Kategori' required data-toggle='tooltip' data-placement='left' title='Sub. Kategori' id='sub_kategori'>
任何人都可以帮助我吗?我无法在任何地方找到代码,而且我无法创建代码来执行此操作。
答案 0 :(得分:0)
要达到预期效果,请使用以下选项
HTML:
<div class="form-group">
<label class="control-label col-sm-3" for="code_oracle">Code Oracle</label>
<div class="col-sm-9">
<input name='code_oracle' type='text' class='form-control' placeholder='Code Oracle' required title='Code Revision Formula' id="code_oracle" value=""></input>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="name_item">Name Item</label>
<div class="col-sm-9">
<input name='name_item' type='text' class='form-control' placeholder='Nama Sample' required title='Name Sample' id="name_item" value="" onkeyup="fill()"></input>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="email">Sub. Category</label>
<div class="col-sm-9">
<input name='category' type='text' class='form-control' placeholder='Sub. Category' required title='Sub. Category' id="category" value=""></input>
</div>
</div>
JS:
var data =[{
"name":"Acesulfame",
"sub":"Sweeteners",
"code":"0001"
},{
"name":"XYZ",
"sub":"abc",
"code":"0002"
},{
"name":"AAA",
"sub":"ZZZ",
"code":"0003"
}]
var fill =function(){
var result = data.filter(function( obj ) {
return obj.name == document.getElementById('name_item').value;
});
document.getElementById('category').value = result[0].sub;
document.getElementById('code_oracle').value =result[0].code;
}
Codepen- http://codepen.io/nagasai/pen/aBrXod