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

106
Views
update text entry automatically on change

I have a simple HTML form with two text entries. I want to copy the text from the first entry field to the second one as soon as the text in the first field changes. Currently the changes are only applied, when I click the second entry. How can I fix this, so that the changes are visible without having to click the second entry?

<!DOCTYPE html>
<html>
    <body>
        <form onchange="myFunction()">
        <label for="field_1">field 1:</label>
        <input type="text" id="field_1" name="field_1"><br><br>
        <label for="field_2">field 2:</label>
        <input type="text" id="field_2" name="field_2"><br><br>
        </form>

        <script>
            function myFunction() {
                var x = document.getElementById("field_1").value;
                document.getElementById("field_2").value = "copy: " + x;
            }
        </script>
    </body>
</html>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Listen for the input event instead:

<!DOCTYPE html>
<html>
    <body>
        <form oninput="myFunction()">
        <label for="field_1">field 1:</label>
        <input type="text" id="field_1" name="field_1"><br><br>
        <label for="field_2">field 2:</label>
        <input type="text" id="field_2" name="field_2"><br><br>
        </form>

        <script>
            function myFunction() {
                var x = document.getElementById("field_1").value;
                document.getElementById("field_2").value = "copy: " + x;
            }
        </script>
    </body>
</html>

about 4 years ago · Juan Pablo Isaza Report

0

Remove your myFunction() it will work. I have already tested it.

<!DOCTYPE html>
<html>
    <body>
        <form>
        <label for="field_1">field 1:</label>
        <input type="text" id="field_1" name="field_1"><br><br>
        <label for="field_2">field 2:</label>
        <input type="text" id="field_2" name="field_2"><br><br>
        </form>

        <script>
            document.getElementById('field_2').addEventListener("click", function() {
             this.value = document.getElementById('field_1').value;
             });

        </script>
    </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!