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
4
votes
2 answers

GetElementsByName with array like name

i often use this notation when i name my controls in order to get an array in POST or GET. so in my scripts i can do
AndreaBogazzi
  • 14,323
  • 3
  • 38
  • 63
4
votes
5 answers

Get only checked element from getElementsByName() in Javascript?

I have a HTML like this: I am trying to get only the checked elements in array like this in Javascript: var choices = []; …
pynovice
  • 7,424
  • 25
  • 69
  • 109
4
votes
4 answers

javascript loop only applying to every other element

i have the following javascript below after i finish an ajax query all of my images have name="pic"