Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda