Sikau

JavaScript · Day 46 · about 30 min

Forms and input

Reading what someone typed.

Let people type

Sign-up forms, search boxes, chat apps: they all read what someone typed. Today you'll read text boxes and handle forms.

Reading .value

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

input.addEventListener("input", () => {
  out.textContent = "Hello, " + input.value;
});

.value is always a string, even if someone types 42. Use Number(input.value) for maths.

The rest of this lesson

  • Forms and submitexplain
  • Validating input in JavaScriptexplain
  • Predictpredict
  • Strings from inputspredict
  • Your turnwrite code
  • Challengechallenge
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript