I was testing some code and realized that I was not able to get the value of a input
through the attribute name document.getElementsByName().value
, but with id
working normally. Is it possible to get the value using name ? If so, how should I do it?
Through the name
function t() {
var t1 = document.getElementsByName("01").value;
var t2 = document.getElementsByName("02");
t2.value = t1;
};
<input type='text' name='01'/><br>
<button onclick='t()'>CONFIRMAR</button><br>
<textarea id='02'></textarea>
Through the id:
function t() {
var t1 = document.getElementById("01").value;
var t2 = document.getElementById("02");
t2.value = t1;
};
<input type='text' id='01'/><br>
<button onclick='t()'>CONFIRMAR</button><br>
<textarea id='02'></textarea>