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

getElementsByName() not working?

I have a Javascript function which should update a hidden input field in my form with a number that increments every time the function is called. It worked originally with getElementById() however because I had to redesign my form I cannot use the…
sqlmole
  • 997
  • 7
  • 17
  • 31
16
votes
6 answers

Javascript: setAttribute() v.s. element.attribute = value to set "name" attribute

So I'm learning to manipulate the DOM and I noticed one interesting thing: Let's say I want to set the name attribute of an element by using the "." dot notation: element.name = "someName"; console.log(document.getElementsByName("someName")[0]); //…
dkugappi
  • 2,664
  • 5
  • 21
  • 22
8
votes
2 answers

On IE document.getElementsByName won't work

I use this code:
And: function clear(element_name){ document.getElementsByName(element_name)[0].innerHTML=""; } It does work in Firefox and…
Marcus
  • 1,222
  • 2
  • 13
  • 22
8
votes
4 answers

Javascript Getting specific element (of parent) by name

I'm using custom tags to define sections in an application, so I have something like this:
I'm using the following and able to get the tag (printed to console, everything…
Fluidbyte
  • 5,162
  • 9
  • 47
  • 76
7
votes
3 answers

How to get id of an element whose name is known in Javascript

I know the name of HTML element but not id. How to fetch id using name of the element using Javascript. Kindly help.
John Watson
  • 869
  • 3
  • 16
  • 32
7
votes
5 answers

Get attribute by name

I have a struct definition with about 25 elements struct X { field 1; field 2; .. }; and I'm trying to fill it with some map values Map A and it appears to be very annoying to do such thing n times X->xx = A["aaa"] …
Skan
  • 71
  • 1
  • 2
7
votes
3 answers

how to access checkboxes and their values with getElementsByName

Suppose I have the following section of a form:



mendahu
  • 163
  • 1
  • 2
  • 6
7
votes
2 answers

how to check if a tag exists using javascript without getting an error

I have xml data with root "clients" and it can contains multiple elements of "client" inside it. sometimes there are no client elements that are returned in the XML file (this is ok). I need to determine if there are any client elements returned so…
VoltzRoad
  • 475
  • 2
  • 6
  • 11
6
votes
3 answers

C# get element by name

So I've figured out how to get an element by id, but I don't know how I can get an element by name. private void SendData() { webBrowser1.Document.GetElementById("textfield1") .SetAttribute("value", textBox1.Text); …
Patric Nøis
  • 208
  • 2
  • 8
  • 27
6
votes
3 answers

jQuery and JSON: getting an element by name

I have the following JSON: var json = { "system" : { "world" : { "actions" : { "hello" : { "src" : "hello world/hello world.js", "command" : "helloWorld" …
Chetan
  • 46,743
  • 31
  • 106
  • 145
5
votes
4 answers

Vanilla JS - Get element by name of a div

I need to translate this jQuery command in JavaScript: $('#edit_pickup_date_modal').find('input[name=type]').val('2'); I tried to: var element = document.getElementById('edit_pickup_date_modal'); var input =…
5
votes
1 answer

Android WebView Compile a Form and submit with Javascript

I'm trying to complete this form : http://www.lbalberti.it/whatsup.asp?codist=57247 I was able to insert value to the two textbox but the button doesn't work. @Override protected void onCreate(Bundle savedInstanceState) { …
5
votes
4 answers

javascript, getelementbyname and focus

I am trying to create function that will look at the username if it is not valid send an alert to the user, clear the username field, and put the username field back into focus. I am trying to do this all with the getElementsBynName() function. It…
Brian
  • 65
  • 1
  • 1
  • 8
4
votes
2 answers

Best Practice: Accessing radio button group

Looking for the best, standards compliant, cross browser compatible, forwards compatible way to access a group of radio buttons in the DOM (this is closely related to my other most recent post...), without the use of any external libraries.
seth
  • 2,741
  • 3
  • 20
  • 15
4
votes
1 answer

Why does Document.prototype.getElementsByName exist in Chrome?

As I know,getElementsByName is a function defined in HTMLDocument,and HTMLDocument inherits from Document,and Document inherits from Node. So why I can see Document.prototype.getElementsByName in Chrome but not Firefox?Does not Chrome implement DOM2…
yanni4night
  • 137
  • 7
1
2 3
8 9