-1
with little knowledge and search I managed to reach this code where I seek to create a DATALIST that when selecting an option of name... Complete the other two fields RG and tel in input automatically ...
I tried so I got... Someone could help me.
var test = [{
name: "Rodrigo",
rg: "00.000",
tel: "(01) 00000-000"
},
{
name: "Monica",
rg: "85.000",
tel: "(02) 00000-000"
},
{
name: "Maria",
rg: "68.000",
tel: "(03) 00000-000"
}
];
var options = '';
for (var i = 0; i < test.length; i++) {
options += '<option value="' + test[i].name + '" />';
document.getElementById('maltList').innerHTML = options;
document.getElementById('rg').value = test[i].rg;
document.getElementById('tel').value = test[i].tel;
}
<input name="malt" list="maltList" />
<datalist id="maltList"></datalist>
<input name="rg" type="text" id="rg"> //
<input name="tel" type="text" id="tel">
The problem is that you set the RG and phone values within the loop where you create the options. Ideally you would do this when the user fills in the name, searching in your array. See about the event
change
input and use it for that.– Woss
...I tried so I got... I think it’s ...I tried and I couldn’t...
– Augusto Vasques
Exactly Augusto, thank you
– Leo Vince