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?
Getting all of the elements in a form # You can get all of the elements in the form by getting the form itself, and then calling the elements property on it. var form = document. querySelector('#my-form'); var elements = form.
The Form Object in HTML DOM is used to represent the HTML < form > element. This tag is used to set or get the properties of < form > element. This element can be accessed by using getElementById() method.
The HTMLFormElement property elements returns an HTMLFormControlsCollection listing all the form controls contained in the <form> element.
document.getElementById("someFormId").elements;
This collection will also contain <select>
, <textarea>
and <button>
elements (among others), but you probably want that.
document.forms["form_name"].getElementsByTagName("input");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With