I need some help for my website. I'm trying to iterate with an array and two different input field. my html file contains like below:
<input name="comune" type="text" id="comune" list="comuni" />
<datalist id="comuni">
</datalist>
<input name="provincia" type="text" id="provincia" />
Let's say that my array is like this:
var comProv = {
'Pisa' : 'PI',
'Firenze' = 'FI',
'Roma' = 'RM'}
I would like to populate the datalist with the Key of the array and, on selection of specific option, I would like to show in the second input field the value of the same array?s item.
I tried with this code
$('#comune').keyup(function(){
var options = '';
for(var i = 0; i < comProv.length; i++){
options += '<option value="'+comProv[i]+'" />';
}
document.getElementById('comuni').innerHTML = options;
});
I stopped without moving to the second topic cause I'm stack. Anyone can help? Thank you in advance.
for...inloop