Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!