bhylu.com

Advertisements

JS HTML Input

Read an input value at the time it is needed. The value property reflects the current field text.

Where to run this

This example changes a document. Open it in the HTML playground, then select Run code. It runs inside a separate preview.

A practical example

HTML + JavaScript

<label for="name">Name</label>
<input id="name">
<p id="hello"></p>
<script>
  document.getElementById("name").addEventListener("input", event => {
    document.getElementById("hello").textContent = "Hello, " + event.target.value;
  });
</script>

What happens

The greeting updates as the visitor types.