getElementsByName method
Gets a collection of objects based on the value of the NAME or ID attribute.
Syntax
var retval = document.getElementsByName(v);Parameters
Return value
Type: IHTMLElementCollection
Returns a collection of objects with the same NAME attribute value.Standards information
- Document Object Model (DOM) Level 1 Specification, Section 2.2
Remarks
When you use the getElementsByName method, all elements in the document that have the specified NAME attribute or ID attribute value are returned.
Elements that support both the NAME attribute and the ID attribute are included in the collection returned by the getElementsByName method, but elements with a NAME expando are not included in the collection; therefore, this method cannot be used to retrieve custom tags by name.
Examples
This example uses the getElementsByName method to return a collection of input type=text elements with the specified NAME attribute value, firstName.
<script> function fnGetNames() { // Returns a collection with 2 INPUT type=text elements. var aInput = document.getElementsByName("firstName"); } </script> <input type="text" name="firstName"> <input type="text" name="firstName"> <input type="button" value="Get Names" onclick="fnGetNames()">
See also
Show: