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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:30:58+00:00 2026-05-16T21:30:58+00:00

Using javascript how do I get the number of elements present with the id

  • 0

Using javascript how do I get the number of elements present with the id of id[x]?

Sample HTML:

<input name="vrow[0]" id="vrow[0]" value="0" type="text"/>
<input name="vrow[1]" id="vrow[1]" value="0" type="text"/>
<input name="vrow[2]" id="vrow[2]" value="0" type="text"/>
<input name="vrow[3]" id="vrow[3]" value="0" type="text"/>

The above html is generated depending on user input. How do I detect how many elements are present using javascript?

Currently I can detect presence of an element like this

Sample Javascript

if(document.getElementById('vrow[0]')){
var row=0;
    }
if(document.getElementById('vrow[1]')){
row=1;
    }
...
  • 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-16T21:30:58+00:00Added an answer on May 16, 2026 at 9:30 pm

    [] are not valid characters in ID attributes in HTML4.01. Even in HTML5, however, you should use the name attribute (without the numeric indexes), and then use getElementsByName():

    <input name="vrow" value="0" type="text"/>
    <input name="vrow" value="0" type="text"/>
    <input name="vrow" value="0" type="text"/>
    <input name="vrow" value="0" type="text"/>
    
    var vrows = document.getElementsByName("vrow");
    alert(vrows.length);

    Note that older versions of IE and Opera may return elements with id attributes that have the same value as the name specified in getElementsByName(). IE may also return non-input elements with a name attribute that has the same value.

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

Sidebar

Related Questions

I'm looking for a way using jquery/javascript to get a class name when I
How to get the parameter value from the URL using Javascript or Jquery whatever
How do I get the selected value from a dropdown list using JavaScript? <form>
I am trying to get the position of SVG elements using Javascript. I have
I have created dynamic elements using javascript. These elements are created when i input
I am using javascript to get the referring page (document.referrer) which works fine and
Is it possible for a web page using Javascript to get data from another
Using javascript, is it possible to get the id of an element by its
I cannot get request specs working when using Javascript. My specs pass if I
I am using javascript for the first time.Actually i want to get the latitude

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.