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

152
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
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