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

151
Views
How can I remove previous stored option tag in Select-Tag when I storing new Option-Tag

In the code below when I'm doing an event change in a <select> tag I'm trying to replace the options inside the when this changes into a different value, the question is, How can I remove the previous store option tag in the <select> tag when am I storing a new <option> tag?

See this image for understanding the problem

const massArray = ["tonne", "Kilogram", "Gram", "Milligram", "Microgram","Imperial ton", "US ton", "Stone", "Pound", "Ounce"]
const areaArray = ["Square kilometer", "Square meter", "Square mile", "Square yard", "Square foot", "Square inch", "Hectare"]

var mainSelect = document.getElementById('mainSelect');

mainSelect.addEventListener("change", () => {
    if (mainSelect.value == "Area") {
        for (let i = 0; i < areaArray.length; i++) {
            const para = document.createElement("option");
            const node = document.createTextNode(areaArray[i]);
            para.appendChild(node);
            const element = document.getElementById("ssSucf");
            element.appendChild(para);

            const para2 = document.createElement("option");
            const node2 = document.createTextNode(areaArray[i]);
            para2.appendChild(node2);
            const secondSelectBox = document.getElementById("secondSelectBox");
            secondSelectBox.appendChild(para2);
        }
    }else if (mainSelect.value == "Mass") {
        
        for (let i = 0; i < massArray.length; i++) {
            const para = document.createElement("option");
            const node  = document.createTextNode(massArray[i]);
            para.appendChild(node);
            const element = document.getElementById("ssSucf");
            element.appendChild(para);

            const para2 = document.createElement("option");
            const node2  = document.createTextNode(massArray[i]);
            para2.appendChild(node2);
            const secondSelectBox = document.getElementById("secondSelectBox");
            secondSelectBox.appendChild(para2);

         }
    }
})
about 4 years ago · Juan Pablo Isaza
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!