We know how to read individual form element items, but let's go a little deeper and actually iterate through an entire form without having to get each element individually.
This is a great way to go through an entire form and do some validation, so feel free to play around with this knowledge. In this tutorial we introduce to you the
.elements property that you can use to access everything inside of a form.
Some example code looks something like this:
var form = document.getElementById("myform").elements; form; //to access the first element: form.type; //retrieve the input type e.g. text, number, etc. form.id; //retrieve the ID of the HTML element
To fork the fiddle and follow along: https://jsfiddle.net/easyjs/hxqqxxn3/
Remember to checkout the Resources section below for associated downloadable content, JSFiddle links, and other resources. Watch the video and follow along!