Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6082405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:17:08+00:00 2026-05-23T11:17:08+00:00

If you have multiple form elements with the same name in a form, the

  • 0

If you have multiple form elements with the same name in a form, the entry in the elements collection on the form ends up being a collection of those fields (which is handy). The DOM2 HTML specification covers the elements collection but doesn’t immediately seem to specify this behavior when there are multiple fields with the same name. Is the behavior covered by a standard (somewhere else in the DOM2 HTML specification, or in another spec)?

For clarity, I’m not asking what the best way to access these fields is. I’m asking whether the fact they end up in a collection (of varying kinds) on the elements collection is covered by a standard, and if so which one.

Example (live copy):

HTML:

<form id="theForm">
<input type="text" name="foo" value="one">
<input type="text" name="foo" value="two">
</form>

JavaScript:

var form = document.getElementById("theForm"),
    foo = form.elements.foo,
    index;
console.log("typeof foo = " + typeof foo);
if (typeof foo !== "undefined") {
  console.log("Object#toString says: " + Object.prototype.toString.call(foo));
}
if ('length' in foo && 'item' in foo) {
  console.log("Looks like a collection of some kind:");
  for (index = 0; index < foo.length; ++index) {
    console.log(index + ": " + foo[index].value);
  }
}

Sample output (for Chrome):

typeof foo = object
Object#toString says: [object NodeList]
Looks like a collection of some kind:
0: one
1: two

I’ve checked IE6, 7, 8, and 9, Firefox 4.0, Firefox 3.6, Chrome 12, Opera 11, and Safari 5. They all make the entry in elements a collection of some kind (Chrome, Firefox, and Safari make it a NodeList [though bizarrely on Safari the typeof is “function” not “object”], and IE and Opera make it an HTMLCollection, but they all have length, item, and [] access). I’m just trying to find the standard, if any, that specifies the behavior.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:17:09+00:00Added an answer on May 23, 2026 at 11:17 am

    It’s covered by the draft HTML5 spec (and the WHAT-WG version), which in this case seems more about documenting how it’s always worked, under the section on HTMLFormControlsCollection (W3C ref, WHAT-WG ref):

    If there are multiple matching items, then a [HTMLFormControlsCollection (W3C ref, WHAT-WG ref) object containing all those elements is returned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with elements like: <div class=row1> <select name=someSelectField multiple=multiple class=selectList> <option
I know that if I have a form with multiple elements with the same
I have a form with multiple fields that I'm validating (some with methods added
I have a form that has multiple fields, and for testing purposes is there
I have a form made up of multiple, optional subparts - each of which
I have a registration form with common registration fields and two multiple selection Lists
Hi I have multiple elements with the same structure in my application. Second div
I've got this HTML form where I have multiple input elements: text, radio, and
How I can combine multiple form elements to one validator? I have address information
I have a html page with multiple similar elements which can be edited in-place:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.