Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get all the elements of a particular form

Tags:

javascript

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?

like image 344
manraj82 Avatar asked Dec 13 '10 16:12

manraj82


People also ask

How do you get all elements in a form?

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.

How do you access the elements of a form using objects?

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.

Which property is used to return all form elements?

The HTMLFormElement property elements returns an HTMLFormControlsCollection listing all the form controls contained in the <form> element.


2 Answers

document.getElementById("someFormId").elements; 

This collection will also contain <select>, <textarea> and <button> elements (among others), but you probably want that.

like image 110
Tim Down Avatar answered Oct 04 '22 23:10

Tim Down


document.forms["form_name"].getElementsByTagName("input"); 
like image 32
esvendsen Avatar answered Oct 05 '22 00:10

esvendsen