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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:23:34+00:00 2026-05-29T22:23:34+00:00

I have all of this code that creates new divs and adds innerHTML. Within

  • 0

I have all of this code that creates new divs and adds innerHTML. Within that, I want to add dropdowns with generated from an XML file. I’m having an issue with dynamically creating the tags inside of inner.HTML.

Now, this is all dynamic and the user is supposed to add new elements as needed. So, as a work around, I have a bunch of var values that process along with each other so things correspond to the same ID’s.

var opselectCounterA = '1';
var opselectCounterB = '1';
var selectCounter = '1';

The tag that I want to add is also within an inner.HTML.

something.innerHTML = "<select id='partSelect" + (selectCounter++) + "'>" + (loadOp) + "</select>";

var selectIDA = "partSelect" + opselectCounterA++;
var selectIDB = "partSelect" + opselectCounterB++;
var loadOp = selectIDA.addOption();

function addOption(){

    selectIDB.innerHTML = "<option>Please work.</option>";

}

Whenever this processes on my HTML page, it shows between the tags as “undefined”.

Why for?

  • 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-29T22:23:34+00:00Added an answer on May 29, 2026 at 10:23 pm

    There are quite a few things wrong with your code (even though I am only seeing a portion of it).

    Regarding the line var loadOp = selectIDA.addOption();…

    1. When this line executes javascript tries to execute a function named addOption() which exists on the selectIDA object. However the selectIDA variable is actually a string that doesn’t have a addOption() function. Because javascript doesn’t find a function named addOption() on the selectIDA object, it sets the value of loadOp to undefined.
    2. Additionally, even if you had written var loadOp = addOption(); instead, the value of loadOp would still be undefined because addOption() doesn’t return any values.

    Perhaps you should try something more along these lines…

    // Function takes a select element and some text as args
    // then adds option elements to the select
    function addOption(select, optionText) {
      var option = document.createElement("option");
      option.innerText = optionText;
      select.appendChild(option);
    }
    
    
    var opselectCounterA = 1;
    opselectCounterA++;
    
    var selectIDA = "partSelect" + opselectCounterA;
    
    // Create the select element
    var selectA = document.createElement("select");
    selectA.setAttribute("id", selectIDA);
    
    // Add options to that select element
    addOption(selectA, "My First Option");
    addOption(selectA, "My Second Option");
    addOption(selectA, "My Third Option");
    
    // Add the select element to the body
    document.body.appendChild(selectA);​
    

    View the working example on jsFiddle: http://jsfiddle.net/Nxezs/

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

Sidebar

Related Questions

I have this piece of code that is giving me trouble. I know all
I have some C# code that generates google maps. This codes looks at all
I have this block of code: users = Array.new users << User.find(:all, :conditions =>
I have this code that reads a file and creates Regex groups. Then I
Hi all I have this code to check if an item from a textbox
I have this code to connect to Active Directory and get all the groups
I have this code which gets WP posts, but it gets all the posts
I have this code: $li = $(li, this) Which is selecting all of the
Problem Hello all! I have this code which takes my jpg image loops through
I have borrowed code from this link PHP regex templating - find all occurrences

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.