JS DOM: input text field

By Xah Lee. Date: . Last updated: .

Input Text Field Example

Result:

Code

<div class="mKvVM">
<label for="input_hnjd">Name:</label>
<input id="input_hnjd" type="text" size="20" maxlength="20" name="user_name" value="" placeholder="Enter name...">
</div>

<div class="mKvVM">
Result:
<span id="output_smjs"></span>
</div>
"use strict";
{
    const input_hnjd = document.getElementById("input_hnjd");
    if (input_hnjd === null)
        throw new Error("id input_hnjd missing");
    const output_smjs = document.getElementById("output_smjs");
    if (output_smjs === null)
        throw new Error("id output_smjs missing");
    const f_update = () => {
        output_smjs.textContent = input_hnjd.value;
    };
    input_hnjd.addEventListener("input", f_update);
    f_update();
}