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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:10:00+00:00 2026-06-06T20:10:00+00:00

function test() { var formHTML =; var frmid =test123; var options = [Test1, Test2,

  • 0
function test()
{
var formHTML ="";
var frmid ="test123";

var options = ["Test1", "Test2", "Test3", "Test4", "Test5"]
formHTML += "<select id='" + frmid + ">";

console.log(options);

for ( i = 0; i < options.length; i++) {
    var temp = options[i];
    var temp2 = "<option value='" + temp + "'>" + temp + "</option>";
    console.log(temp2);
    formHTML += temp2;
}
formHTML += "</select>";
console.log(formHTML); 
document.getElementById("injected").innerHTML+=formHTML;

}

Above is my function to make a select element in my page, when i call this function there is a very strange issue, it only dispalys options test2,test3,test4,test5 and not one…

When i print out formHTML using console.log it shows..

<select id='test123><option value='Test1'>Test1</option>
<option value='Test2'>Test2</option>
<option value='Test3'>Test3</option>
<option value='Test4'>Test4</option>
<option value='Test5'>Test5</option>
</select> 

But if you run the code and look at the source code the HTML element is not correct the first element looks like

 <option value='test1'> Test1

Missing the close option tag,

I have tried debugging and changing code around but this issue has left me confused.

Is there something missing is there better way of going about this? I am trying to store it all in one string before manipulating the DOM for speed reasons.
All help is appreciated, Thanks

  • 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-06-06T20:10:01+00:00Added an answer on June 6, 2026 at 8:10 pm

    YOu have an error in this line

    formHTML += "<select id='" + frmid + ">";
    

    Change that to

    formHTML += "<select id='" + frmid + "'>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

var test = { } $(test).on(testEvent, function (){ console.log(testEvent has fired); }); $.event.trigger(testEvent); I
This is the working code: var test = function () { console.log(test.data); }; test.data
If I do function test() { var fromDate=01/17/2012; var res= Test1(fromDate); return false; }
why does this only alert 1 ? function test() { var myobj = {
Why doesn't this work right? function test() { var start = new Date(2012, 3,
I am trying to sort a table with JavaScript. function test() { var table
function test(){ if(true){ var a = 5; } alert(a); } test(); I keep getting
Here is the code which test in IE8: var stack = []; function test()
Consider a simple JS function as function test(property, color) { var element = document.getElementById(test);
Consider we have a simple cycling Javascript process as: function test() { el=document.getElementById("test"); var

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.