2.1.9 Accessing Form Fields

In JavaScript, we want to access out form fields so we can do things like checking for proper data, or form validation. Imagine we have a form on our page that is a user login form…

We grab our form from the DOM…

We add our submit event listener…

We can grab our form field elements using array notation and store them in variables. We can then access their values from those variables.