Eu estava testando uns códigos e percebi que não estava conseguindo obter o valor de um input
através do atributo name document.getElementsByName().value
, mas com o id
está funcionando normalmente. É possível obter o valor usando name? Se sim como devo fazer?
Através do 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>
Através do 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>