getElementsByName Method

MS Office DHTML, HTML & CSS

getElementsByName Method

Retrieves a collection of objects based on the value of the NAME attribute.

Syntax

collObjects = document.getElementsByName(sNameValue)

Parameters

sNameValueRequired. String that specifies the value of a NAME attribute.

Return Value

Returns a collection of objects with the same NAME attribute value.

Remarks

When you use the getElementsByName method, all elements in the document that have the specified NAME attribute value are returned.

Elements that support the NAME attribute are included in the collection returned by the getElementsByName method, but not elements with a NAME expando.

Example

This example uses the getElementsByName method to return a collection of INPUT type=text elements with the specified NAME attribute value, firstName.

Sample Code

<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()">

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.
document

See Also

document object model overviewInternet Link


Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.