Forms and JavaScript: Inspect the value of an item

In this unit I’ll show you how to use JavaScript to interact with a form.

Let’s start with the simple form we defined in the Introduction to Forms unit:

<form>
  <input type="text" name="city" />
</form>

Using the DOM API and in particular querySelector, we can get the value typed into this input field:

document.querySelector('input').value

This is often used along with events.

Lessons in this unit:

0: Introduction
1: ▶︎ Inspect the value of an item
2: Listen to events on input fields
3: Intercepting a form submit event using JavaScript
Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. Launching May 21, 2024. Join the waiting list!