Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
how to Avoid HTML [object HTMLOptionElement]

I'm trying to collect all the option from one select element and insert them dynamically to another select element.

    <select name="" id="main-products-images-standards-select">
        <option value="1">Name 1</option>
        <option value="2">Name 2</option>
        <option value="3">Name 3</option>
    </select>

    <select name="" id=""></select>

var  main_products_images_standards_select = document.getElementById('main-products-images-standards-select').options 
var standards = '';
   for(var i = 0 ; i < main_products_images_standards_select.length ; i++)
    {
            standards += main_products_images_standards_select[i];
    }

when I print each option in the loop I get the required results, but as I collect them together I'm ending up with the next results

[object HTMLOptionElement][object HTMLOptionElement][object HTMLOptionElement][object HTMLOptionElement]

What should I do to avoid those results Thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use .value to get the value of option

var main_products = document.getElementById('main-products')
var standards = '';
for (var i = 0; i < main_products.length; i++) {
  standards += main_products[i].value;
  document.getElementById('demo').innerHTML = standards;
}
<select name="borderStyle" id="main-products">
  <option value="solid">solid</option>
  <option value="dotted">dotted</option>
  <option value="dashed">dashed</option>
</select>
<div id="demo"></div>

Update

If you want to reprint the select with same options then use outerHTML on the id

You can use loop to run or have select number of times you have option or how many times you want

var main_products = document.getElementById('main-products')
document.getElementById('demo').innerHTML = main_products.outerHTML;
<select name="borderStyle" id="main-products">
  <option value="solid">solid</option>
  <option value="dotted">dotted</option>
  <option value="dashed">dashed</option>
</select>
<div id="demo"></div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!