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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:02:54+00:00 2026-05-24T17:02:54+00:00

I would like to be able to use javascript to find every id (or

  • 0

I would like to be able to use javascript to find every id (or name) for every object in an html document so that they can be printed at the bottom of the page.

To understand more fully what I’m trying to accomplish, let me explain. I build large forms from time to time for things such as property applications, rental listings, detailed medical website user registration forms and such. As I do it now, I build the form, assign the id’s and names and decide which values are required and such. Then when I build the php form validation and database insert portion for the form, I’ve been manually going through the html and pulling out all of the id’s to reference from the $_post array for the input validation and database insert. This has been very time consuming and a real pain, often laced with typing errors.

The form I’m working on currently is just too big, and I’d much rather write a javascript function that I can run on my local copy of the page to list all of the id’s so that I don’t have to copy and paste them one by one, or write them down. I could then also use the javascript loop to event print out the php code around the id names so that I’d only have to copy the list and lightly edit out the id’s I dodn’t need… I hope you guys get the idea.

Any suggestions on how I can drop all of the id’s into an array, or if there is already an array I can access and loop through (I couldn’t find anything on google). Also, any suggestions for how to speed up the process of producing large forms with a work flow that generates the php or makes it quicker than my current method would be greatly appreciated!

  • 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-24T17:02:54+00:00Added an answer on May 24, 2026 at 5:02 pm

    On modern browsers you can do this via

    document.querySelectorAll('*[id]')
    

    should do the job.

    If you need all descendants of myElement with IDs, then do

    myElement.querySelectorAll('*[id]')
    

    If you want to be really careful to exclude <span id="">, then maybe

    document.querySelectorAll('*[id]:not([id=""])')
    

    If compatibility with older browsers is required

    var allElements = document.getElementsByTagName("*");
    var allIds = [];
    for (var i = 0, n = allElements.length; i < n; ++i) {
      var el = allElements[i];
      if (el.id) { allIds.push(el.id); }
    }
    

    should leave you with all the IDs in allIds.

    If you find you need to just enumerate the IDs under a particular form node, then you can replace document.getElementsByTagName with myFormNode.getElementsByTagName.

    If you want to include both IDs and NAMEs, then put

    else if (el.name) { allIds.push(el.name); }
    

    below the if above.

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

Sidebar

Related Questions

I'm writing a component that I would like to be able to use in
I would like to be able to use the Tab key within a text
I would like to be able to use the same Session variable when transferring
I'm new to the iPhone and I would like to be able to use
I would like to be able to define and use a custom type in
This is really just for my own use: I would like to be able
It doesn't look like basic javascript but nor can I use JQuery commands like
I need to make a Javascript object that would behave as an associative array,
I would like to be able to add custom snippets of javascript to any
Would like to be able to set colors of headings and such, different font

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.