A
A
Anto2018-03-22 18:18:01
JavaScript
Anto, 2018-03-22 18:18:01

How to duplicate text entered in a form?

Greetings!
Tell me there is fom and it has text fields with a phone number, how to make it so that when entering data into the form, they are duplicated elsewhere on the page, say at the bottom of the site page.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-03-22
@ZIROKUL

You hang an input event handler on the input field, in which you write value where you need it. Something like this:

<form>
  <div><input data-output="#output1"></div>
  <div><input data-output="#output2"></div>
  <div><textarea data-output="#output3"></textarea></div>
</form>

<div id="output1"></div>
<div id="output2"></div>
<div id="output3"></div>

document.querySelector('form').addEventListener('input', function(e) {
  const output = document.querySelector(e.target.dataset.output);
  if (output) {
    output.innerHTML = e.target.value;
  }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question