Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda