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

87
Visualizações
Exit $('input[name^="myname"]').each( function() {

I need to exit the javascript but am getting something odd.

There is an array of inputs that this uses.

When the "if" statement is true and "return true" or "return false" is to run, the alert('something') runs and I see the pop-up.

The script continues to execute.

I don't know if it stills executes the "..each" loop. Do you?

This needs to exit the .each loop and script entirely.

If no checkbox is false, then run the alert code outside the ...each(function()...

<input type="checkbox" id="a" name="test[]" onclick="myfunction('a');" />
<input type="checkbox" id="b" name="test[]" onclick="myfunction('b');" />
<input type="checkbox" id="c" name="test[]" onclick="myfunction('c');" />

and the script...

<script>
function myfunction(instuff) {
    $('input[name^="test"]').each(function() {
        if ($(this).prop('checked')  == false) {
            //...run code...
            return true; //return false; acts the same.
        }
    })
    //...run other code...
    alert('something');
}
</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

return false from the callback function will stop the .each() loop. But the rest of myfunction() will continue to run.

If you want to stop the rest of the function, you can set a variable that you check after the loop.

function myfunction(instuff) {
  let stop = false;
  $('input[name^="test"]').each(function() {
      if (!$(this).prop('checked')) {
        stop = true;
        return false;
      }
    } // fixed the code typo
  )
  if (stop) {
    return;
  }
  //...run other code...
  alert('something');
}

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