Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
stop resetting select input whenever new select option is added when button is click

I successfully create new select if the button is click. but how do i stop the selected being refresh whenever I add another select?

it's kind hard for me to explain but here's the code:

<body>
<table>
    <tr>
        <td class="here" colspan="2"> </td>
</tr>
    <tr>
        <td colspan="2" ><a style="color: #4F7942; cursor: pointer;" onclick="add()">Add Select</a></td>
    </tr>
</table>
function add(){
var container = document.querySelector(".here");

if(container){
    container.innerHTML += `
    <table>
        <tr>
            <td>
                <select class="abc" name="any[]">
                    <option value="" selected disabled>Select....</option>
                    <option>1</option>
                    <option>2</option>
                    <option>3</option>
                </select>
            </td>
        </tr>
    </table>
    `;
}

}

https://jsfiddle.net/idfrnffnd/akjpLc2y/4/

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You should not alter innerHTMl, instead, use container.insertAdjacentHTML

function add(){
    var container = document.querySelector(".here");
    
    if(container){
        container.insertAdjacentHTML('beforeend', `
        <table>
          <tr>
              <td>
                <select class="abc" name="any[]">
                  <option value="" selected disabled>Select....</option>
                  <option>1</option>
                  <option>2</option>
                  <option>3</option>
              </td>
            </tr>
        </table>
        `);
    }
}
<table>
  <tr>
      <td class="here" colspan="2"> </td>
  </tr>
  <tr>
    <td colspan="2" ><a style="color: #4F7942; cursor: pointer;" onclick="add()">Add Select</a></td>
  </tr>
</table>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda