In other words, instead of form.elements.login we can write form.login. Here's how to get element in a HTML. HTMLFormElement.method 1. While using W3Schools, you agree to have read and accepted our. text/plain : Introduced by HTML5 for debugging purposes. var inputs = document.getElementById("my-form").elements; var inputByIndex = inputs[0]; var inputByName = inputs["username"]; HTMLFormElement.lengthRead only 1. The getElementById and getElementsByName methods can be used to obtain references to forms and form elements. The getElementById method returns the single matching element with the specified ID; getElementsByName returns an array-like list of elementsthat match the name specified. Some example code looks something like this: var form = document.getElementById("myform").elements; form[0]; //to access the first element: form[0].type; //retrieve the input type e.g. Forms and control elements, such as have a lot of special properties and events. Here is a table overview of the five methods we will cover in this tutorial.It is important when studying the DOM to type the examples on your own computer to ensure that you are understanding and retaining the information you learn.You can save this HTML file, access.html, to your own project to work through the examples along with this article. The document.forms[index] also returns the form element by a numerical index. https://html.spec.whatwg.org/multipage/forms.html#the-select-element, https://html.spec.whatwg.org/multipage/forms.html, video courses on JavaScript and Frameworks. For any element, the form is available as element.form. oForm = document.forms [index]; To get the value of the text input element, we can use the value property of the text input object: text_val = oText.value; As an example, if we have the following text input element: . We have to click the 'Click me!' The elements in the collection are sorted as they appear in the source code. The first form is forms[0], thesecond is formsetc. Unlike most other controls,