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?
This collection will also contain
<select>
,<textarea>
and<button>
elements (among others), but you probably want that.If you have a reference to any field in the form or an event then you don't need to explicitly look up the form since every form field has a
form
attribute that points to its parent form.If you have an event then it will contain a
target
attribute which will point to the form field that triggered it, which means you can access the form viamyEvent.target.form
.Here is an example without any form lookup code.
Try this to get all the form fields.
How would you like to differentiate between forms? You can use different IDs, and then use this function:
SIMPLE Form code
Javascript Code
JSFIDDLE : http://jsfiddle.net/rng0hpss/