Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

306
Visualizações
How to get the object value on my text input?

var fname = document.getElementById("fName");
var lname = document.getElementById("lName");
const btnSave = document.getElementById("btnSave");
const btnDisplay = document.getElementById("btnDisplay");

btnSave.addEventListener("click", getData);

function getData() {
  console.log(
    getFullName({
      fname: `${fname.value}`,
      lname: `${lname.value}`,
    })
  );
}

function getFullName(FullName) {
  return FullName.fname + " " + FullName.lname;
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="main.css" />
  </head>
  <body>
    <input type="fName" placeholder="First Name" />
    <input type="lName" placeholder="Last Name" />
    <button id="btnSave">Save</button>
    <button id="btnDisplay">Display</button>

    <script src="main.js"></script>
  </body>
</html>

How to get the object value on my text input? It returns null. But when I assign value on my object like fName: "John", lName: "Doe" It returns successfully.

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

"fname" and "lname" are not ids. You have incorrectly assigned types on your input fields. Instead do something like this:

<input type="text" id="fname" placeholder="First Name" />
<input type="text" id="lname" placeholder="Last Name" />

about 4 years ago · Santiago Trujillo Relatório

0

Your input elements do not have ids.

about 4 years ago · Santiago Trujillo Relatório

0

You did not add id to your input tags.

try :

    <input id="fName" placeholder="First Name" />
    <input id="lName" placeholder="Last Name" />
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda