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();
}
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("&"));
}
}
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.