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 8795537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:24:32+00:00 2026-06-13T23:24:32+00:00

I was trying to group a set of INPUT-elements in a Javascript array and

  • 0

I was trying to group a set of INPUT-elements in a Javascript array and got confused on why I got a multi-dimensional array back (array named ‘urls’ in the code below).
It turned out I had mixed up the fourth element with the same id as the first element.

<html>

<head>
    <script language="javascript">
    function validate() {
        var form = document.forms.conf;

        var urls = new Array(form.url1, form.url2, form.url3, form.url4);
        alert(urls[0].value);  // returns 'undefined'
        alert(urls[0][0].value);  // works
    }
    </script>
</head>

<body>

<form name="conf">
    <input type="text" name="url1" id="url1">
    <input type="text" name="url2" id="url2">
    <input type="text" name="url3" id="url3">
    <input type="text" name="url4" id="url1"><br />
    <button type="button" onclick="javascript:validate();">Push me</button>
</form>

</body>
</html

My question is, why does this happen? What relationship does the HTML attribute ‘id’ have to ‘document.forms.form_name.element’? And why does it cause it to put it in a multi-dimensional array?
The behavior seems to be the same cross-browser too, so it have to be some definition I’m not aware of.

  • 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-06-13T23:24:33+00:00Added an answer on June 13, 2026 at 11:24 pm

    A form will have a property for each form control that has a name or id. The name of that property will be the same as the name or id. If multiple elements share a name (or, illegally, an id) then the property will contain an NodeList instead of a single HTMLElementNode.

    The first input has the name (and id) url1.
    The last input has the id url1

    So form.url1 becomes a NodeList consisting of those two elements.

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

Sidebar

Related Questions

I'm trying to group a set of data based on the range of an
I'm trying to set the init_connect parameter to SET NAMES utf8 rds-modify-db-parameter-group mygroup --parameters=name=init_connect,
I a trying to set my group of checkboxes enabled when the value is
I am trying to iterate each named group in a regular expression (i.e. -
I'm trying to reorder/group a set of results using SQL. I have a few
I'm trying to group together radiobuttons that are creating using a for loop and
I'm trying to group some sets in disjoint sets. For example, if I have
I am trying to group some data without much luck. I have a list
I am trying to group a data collection and send it to the View
I'm trying to group down records by their priority levels, e.g. --- Priority: High

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.