javascript getElementsByName

getElementsByName

The document.getElementsByName(name) is a method of the document object that is used to get an element by its name.

Syntax:

document.getElementsByName(name)

Example:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
function fruitname()
{
var allfruits =document.getElementsByName("fruit");
alert("Total Fruits:"+allfruits.length);
}
</script>
<form>
BANANA:<input type="radio" name="fruit" value="BANANA">
APPLE:<input type="radio" name="fruit" value="APPLE">
MANGO:<input type="radio" name="fruit" value="MANGO">
STRAWBERRY:<input type="radio" name="fruit" value="STRAWBERRY">
<input type="button" onclick="fruitname()" value="Total Fruits">
</form>
</body>
</html>
Please follow and like us:
Content Protection by DMCA.com