function getInputElements() {
var inputs = document.getElementsByTagName("input");
}
The above code gets all the input
elements on a page which has more than one form. How do I get the input
elements of a particular form using plain JavaScript?
You're all concentrating on the word 'get' in the question. Try the 'elements' property of any form which is a collection that you can iterate through i.e. you write your own 'get' function.
Example:
Hope that helps.
If you only want form elements that have a
name
attribute, you can filter the form elements.First, get all the elements
Second, do something with them
If you want to use a form, rather than the entire body of the page, you can do it like this
It is also possible to use this:
All the elements of forms are stored in an array by Javascript. This takes the elements from the first form and stores each value into a unique variable.
Use this
The el stands for the particular form element. It is better to use this than the foreach loop, as the foreach loop also returns a function as one of the element. However this only returns the DOM elements of the form.