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

216
Visualizações
what should I do make it print output

document.addEventListener('DOMContentLoaded', function() {
  var test = document.getElementById("myText").value;
  var mapObj = {
    A: 'Eh'
  };

  test = test.replace(/A/g,
    function(matched) {
      return mapObj[matched];

    })

  var check = document.getElementById("check");
  check.addEventListener('click', function() {
    document.getElementById('demo').innerText = test;
  }, false);
}, false);
BODY {
  width: 520px;
  min-height: 250px;
}
<html>

<body>
  <textarea rows="10" cols="50" id="myText"></textarea>


  <button id="check">translate</button>

  <textarea rows="10" cols="50" id='demo' readonly><p id='demo'></p></textarea>


</body>

</html>

it's a part of my code, it's a translator
it is supposed to work as I click the translate button then print the output in the textarea box but it doesn't what should I do make it work? I would appreciate the answer in any types very much

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

0

Your test variable didn't get updated when you press the button. I've changed the code a bit to give you the idea from where to start. Take a look:

document.addEventListener('DOMContentLoaded', function() {
  var check = document.getElementById("check");
  check.addEventListener('click', function() {
    var test = document.getElementById("myText").value;
    var mapObj = {
      A: 'Eh'
    };

    test = test.replace(/A/g,
      function(matched) {
        return mapObj[matched];

    })
    
    document.getElementById('demo').innerText = test;
  }, false);
}, false);
BODY {
  width: 520px;
  min-height: 250px;
}
<html>

<body>
  <textarea rows="10" cols="50" id="myText">Type "A" and press translate.</textarea>


  <button id="check">translate</button>

  <textarea rows="10" cols="50" id='demo' readonly></textarea>


</body>

</html>

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