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

98
Visualizações
How to make default value in the textarea change/autofill when the input text field is filled?

For example on input like this:

<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body>
<div class="container">
  <div class="form-group my-2">
      <input class="form-control mx-2" type="text" placeholder="Customer Name">
  </div>
  <div class="form-group mb-2">
      <input class="form-control mx-2" type="email" placeholder="Customer Email">
  </div>
  <div class="form-group mb-2">
      <input class="form-control mx-2" type="text" placeholder="Customer pin">
  </div>
  <div class="form-group mb-2">
      <textarea class="form-control mx-2" rows="4">
Hi, {customer Name here}
Your Email is: {customer Email here}
Your Pin is:  {customer pin here}
      </textarea>
  </div>
</div>
</body>

  • When the Customer Name input is entered: John Doe
  • When the Customer Email input is entered: johndoe@mail.com
  • When the Customer pin input is entered: 123

Then the textarea value should become

Hi, John Doe
Your Email is: johndoe@mail.com
Your Pin is: 123

How would I autofill the textarea with the data that the user inputted?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to use JavaScript. It will build your complete textarea content from the inputted values whenever they are updated. Like this:

// Input elements
var customerName = document.getElementById("customer-name");
var customerEmail = document.getElementById("customer-email");
var customerPin = document.getElementById("customer-pin");

// Output textarea
var customerInfo = document.getElementById("customer-info");

function updateTextareaContent(){
  customerInfo.value=`Hi, ${customerName.value||"(enter name)"}
Your Email is: ${customerEmail.value||"(enter email)"}
Your Pin is: ${customerPin.value||"(enter pin)"}`;
}

customerName.addEventListener("keydown", updateTextareaContent);
customerEmail.addEventListener("keydown", updateTextareaContent);
customerPin.addEventListener("keydown", updateTextareaContent);

customerName.addEventListener("keyup", updateTextareaContent);
customerEmail.addEventListener("keyup", updateTextareaContent);
customerPin.addEventListener("keyup", updateTextareaContent);
<!DOCTYPE html>
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body>
<div class="container">
  <div class="form-group my-2">
      <input class="form-control mx-2" type="text" placeholder="Customer Name" id="customer-name">
  </div>
  <div class="form-group mb-2">
      <input class="form-control mx-2" type="email" placeholder="Customer Email" id="customer-email">
  </div>
  <div class="form-group mb-2">
      <input class="form-control mx-2" type="text" placeholder="Customer pin" id="customer-pin">
  </div>
  <div class="form-group mb-2">
      <textarea class="form-control mx-2" rows="4" id="customer-info">
Hi, (enter name)
Your Email is: (enter email)
Your Pin is: (enter pin)
      </textarea>
  </div>
</div>
</body>

</html>

(The snippet is a bit large so it is collapsed, click the arrow to open it)

This watches for changes in the text, and when those changes happen, it updates the textarea.

Here's some further reading in order to more better understand the code snippet:

  • Event Listeners on w3schools

  • keydown and keyup events on MDN

  • Template Literals on MDN

about 4 years ago · Juan Pablo Isaza 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