How to replace the key of an array with a variable? [closed]

2

This works:

var ind = 0;
var elementos = document.getElementsByName('significado');
var sig_txt = elementos[0].value;
alert(sig_txt);

returns "wood"

Why does not this work?

var ind = 0;
var elementos = document.getElementsByName('significado');
var sig_txt = elementos[ind].value;
alert(sig_txt);

HTML:

<input type="text" name="significado"  value="madeira">
<input type="text" name="significado"  value="pedra">
<input type="text" name="significado"  value="cimento">
    
asked by anonymous 20.07.2017 / 00:24

0 answers