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

150
Visualizações
perform multiple actions within an if

How can I perform all the actions in the same if? currently only performs the last

if (test==1) {
    document.getElementById("opciones").action='1ExcelArchivos.php'; 
    document.getElementById("opciones").submit();
    document.getElementById("opciones").action='2ExcelArchivos.php'; 
    document.getElementById("opciones").submit();
    document.getElementById("opciones").action='3ExcelArchivos.php'; 
    document.getElementById("opciones").submit();
    document.getElementById("opciones").action='4ExcelArchivos.php'; 
    document.getElementById("opciones").submit();
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can try sending by XMLHttpRequest

if (test == 1) {
  var f = document.getElementById("opciones");
  var postData = [];
  for (var i = 0; i < f.elements.length; i++) {
    postData.push(f.elements[i].name + "=" + f.elements[i].value);
  }
  var to = ['1ExcelArchivos.php', '2ExcelArchivos.php', '3ExcelArchivos.php', '4ExcelArchivos.php'];
  for (var i = 0; i < to.length; i++) {
    var xhr = new XMLHttpRequest();
    xhr.open("POST", to[i], true);
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.send(postData.join("&"));
  }
}
about 4 years ago · Juan Pablo Isaza Relatório

0

This depends a bit what the PHP endpoints are doing, but eventually it is possible to group those files.

Example:

ExcelArchivos.php:

<?php
require __DIR__ . '/1ExcelArchivos.php';
require __DIR__ . '/2ExcelArchivos.php';
require __DIR__ . '/3ExcelArchivos.php';
require __DIR__ . '/4ExcelArchivos.php';
if (test==1) {
    document.getElementById("opciones").action='ExcelArchivos.php'; 
    document.getElementById("opciones").submit();
}

Whether the PHP example is directly fitting or there is a different approach necessary, if at the end of the day you have one endpoint instead of four, you can process this with a single submit.

The browser normally can only process one submit() action at a time as it is related to navigation and there is only one way to navigate. This is also the reason why the last submit() did superseede the earlier ones.

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