I'm new here and curious in programming, so sorry to talk bullshit, but I need help.
I have a form with the option to insert inputs dynamically.
Whenever an "item" is added, two inputs are added, the "foo" and the "bar" .
All "foo" relate to the datalist "list" .
All "bar" are inactive and their value should always be changed when the "foo" value changes.
HTML INPUTS:
<div id="lista">
<div>
<input name="foo[]" list="dList" type="text">
<inpu name="bar[]" disabled="" type="text">
</div>
<div>
<input name="foo[]" list="dList" type="text">
<inpu name="bar[]" disabled="" type="text">
</div>
</div>
<datalist id="dList">
<option label="Item 1" datavalue="1" value="Item 1">
<option label="Item 2" datavalue="2" value="Item 2">
</datalist>
The only way I found to get the (dynamic) inputs was:
input = $('#listaServicos').find(':input'); // array de inputs
// aqui tereis tanto os _"foo"_ quanto os _"bar"_
And then make a for
working with them:
valores = [[1,3000],[2,5000],[3,4000],[4,10000],[5,10000]];
for (i = 0; i < input.length; i++) {
name = input[i].name;
console.log("name: "+ name);
if(name.indexOf('foo') > -1){
// aqui preciso pegar o atributo _"datavalue"_ do datalist
// correspondente, comparar com a key array valores
//e preencher o _"bar"_ com o valor
}
}
The biggest problem is to relate the "foo" to the datalist, as foo and "bar" will always be in the same subarray.
Thanks in advance for any help you want come