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

  • Home
  • SEARCH
  • 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 3627916
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:56:57+00:00 2026-05-18T23:56:57+00:00

This is a relatively straightforward task I’d like to accomplish without jquery or AJAX.

  • 0

This is a relatively straightforward task I’d like to accomplish without jquery or AJAX.

I have a couple javascript arrays A and B, and I have multiple rows in an HTML form that each contain two columns containing dropdowns which will each contain the contents of A and B. I’d like to populate every dropdown of a certain name with a predefined set of items. This can be done after the page has already loaded.

Any ideas as to what the javascript would look like? How can I address a slew of items named one thing?

  • 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-18T23:56:58+00:00Added an answer on May 18, 2026 at 11:56 pm

    This is the code for one of your arrays:

    // String values; can be used as name, id, or innerHTML 
    var valsA = ['one','two','three'];
    // Variable to store <option> object
    var opt;
    
    // Loop through vals and make an <option> for each one
    for(var i=0;i<valsA.length;i++) {
      // Create node
      opt = document.createElement("OPTION");
      // Set innerHTML, if you want
      opt.innerHTML = valsA[i];
      // Set the names to be all the same, if you want
      opt.setAttribute("name","oneThing");
      // Set unique ID, somehow, if you want
      opt.id = "value"+i+valsA[i];
      // Finally, append <option> to dropdown menu
      document.getElementById('myDropdown').appendChild(opt);
    }
    

    Your HTML should have a <select id='myDropdown'></select> ready to go before this script is run. You can do the same process for the other array.

    Also, keep in mind that names

    • are not necessarily unique
    • can be used to get groups of items

    while IDs

    • should be unique
    • unfortunately your script will run if they’re not, this can be a source of errors
    • should be used to get a single object

    So, make sure each of your dropdowns has a unique ID so your script can find it correctly.

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

Sidebar

Related Questions

I'm wondering whether something like this is possible (and relatively easy to do), and
I have a relatively complex .htaccess file to control page requests, this currently redirects
I'm relatively new to the Python world, but this seems very straight forward. Google
I realised this might be relatively niche, but maybe that's why this is good
I'm sure this is a relatively simple question, and there must be a good
I'm relatively new to web application programming so I hope this question isn't too
Being relatively new to functional programming, I expend lots of energy wondering is this
Without arguing the relative merits of storing a datetime this way... If you had
How can I have a relative path in the web.config file. This value is
I am rephrasing this question to make it a little more straightforward and easy

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.