Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!