How to use Document getElementsByName in JavaScript
This article describe about Document getElementsByName() Method in JavaScript.
Document getElementsByName() Method
For access all element with a specific name use getElementsByName() method.
Syntax
document.getElementsByName(name)
|
Parameter |
Description |
name |
Required. Access element name. |
Example
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function getElements() {
var x = document.getElementsByName("x");
alert(x.length);
}
</script>
</head>
<body>
Cow:
<input name="x" type="radio" value="Cow" />
Ox:
<input name="x" type="radio" value="Ox" />
horse:
<input name ="x" type ="radio" value ="horse" />
<input type="button" onclick="getElements()" value="How many elements named 'x'?" />
</body>
</html>
|
Output
Note: After click on the button output become.

You may also want to read these related articles Click here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here