Home > Software engineering >  displaying value of an input on the form page without clicking submit
displaying value of an input on the form page without clicking submit

Time:06-10

I’m creating a form. How can I make the value of an input display on the form page without clicking the submit button using php and maybe JavaScript

CodePudding user response:

Add an input event listener to the field and output it where needed.

const input = document.querySelector("#in");
const output = document.querySelector("#out");

input.addEventListener("input", (e) => {
  output.textContent = e.target.value;
});
<p>Type text here: <input id="in" /></p>
<p>See result here: <span id="out"></span></p>

  • Related