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 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 am sure there must be a relatively straightforward way to do this, but
I hope this is a relatively easy problem although I have spent hours websearching
I have a web service, defined(WSDL) and implemented in PHP. This one is relatively
Hopefully this is simple: I have a relatively long list where each list item
I am building a project which requires multiple database support. This has been relatively
I've got quite a lot of code here, but it's relatively straightforward. This is
I'm sure this is relatively easy and straightforward, but I'm having no success figuring
I'm relatively new to the Python world, but this seems very straight forward. Google
I'm using WCF through Spring.net WCF integration link text This works relatively fine, however
I realised this might be relatively niche, but maybe that's why this is good

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.