Questions tagged [getelementsbyname]

In JavaScript and VBScript, the getElementsByName is a function which is used to access all HTML elements with a specified name. Two different elements can be declared with same name unlike their Id which must be defined unique. Tag getElementsByName can be used for usage related problems of getElementsByName function.

Wiki:

The getElementsByName() is a JavaScript and VBScript function which can be used in web pages to accesses html elements with their specified name. The getElementsByName method is supported in all major browsers. The function getElementsByName() can be used to access more than one element because html elements can be defined with same name unlike theirIDs which should be defined unique.

Syntax usage:

document.getElementsByName('name')

Example:

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

Cats:
  <input name="x" type="radio" value="Cats">
Dogs:
  <input name="x" type="radio" value="Dogs">
  <input type="button" onclick="getElements()" value="Elements with name 'x'?">

</body>
</html>

Tag usage:

The tag can be used for programming problems related to usage of getElementsByName function. Tag should be avoided for theoretical and opinion based questions.

Read more:

134 questions
-1
votes
3 answers

JS replace all matching id values

A website has multiple pages with imported HTML from another page with id tags that need to be simplified. It currently looks like this.

Anything

-1
votes
3 answers

How to use getElementById to get the elements in a form?

I am wondering why in the following script comment 1 and comment 2 dosent work I know that we can access directly element by id without passing by "form" however am asking the question for educational purpose Thank you
-1
votes
4 answers

How to change Element by tag name with javascript from iframe

I am trying to change url(herf) from style . Check it