Blog

getElementsByName() property in HTML

Posted by Mahak Gupta Blogs | HTML 5 Mar 01, 2012
getElementsByName() property access all elements which we will specify in it.
Download Files: getElementByName.rar
getElementsByName()  property access all elements which we will specify in it.

<html>
<head>
<script type="text/javascript">
function getNumberOfElements()
{
var x=document.getElementsByName("btn");
alert(x.length);
}
</script>
</head>
<body>


<input name="btn" type="button" value="First" />
<input name="btn" type="button" value="Second" />
<input name="btn1" type="button" value="Third" />
<input name="btn" type="button" value="Forth" />
<input name="btn" type="button" value="Fifth" />
<input name="btn" type="button" value="Sixth" /><br /><br /> 
<input type="button" onclick="getNumberOfElements()" value="Click here to find the number of elements that have the same name" />

</body>
</html>



In this example the alert box shows the number of button element (btn).

1.png
comments
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter