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

246
Views
html, javascript - open a new tab every time a form gets submitted using Post method

I have an html form with a select field where user selects which table we'll show him/her from the mySql database.

<form action = "tableOutput.php" method="post" name="frmTableSelect" target="_blank"> 
        <p>Select a table from the list</p>
        <select name="tableName" autofocus>
    <!-- here I load a list of tables from mySql. for simplicity let it be: -->
            <option>table 1</option>
        <option>table 2</option>
         <p><br><input name="submit" type="submit" id="knopka" value="show table"></p>
     </form>

Like this, when user hits the button, a new tab opens up where the selected table gets printed (I process it in "tableOutput.php") - this is fine.

But the user needs to return to the first form and select another table, that should be printed in another tab, whereas it gets printed in the same tab as the first one replacing it. In other words, we need to be able to open many new tabs with output.

I inserted this javascript:

    <script>
      knopka.onclick = function() { 
        window.open("tableOutput.php")
      };
    </script>

Now a tab gets open every time one hits the button, but the POST method in "tableOutput.php" does not work anymore, so we get an error while processing the query.

If I write

<script>
  knopka.submit = function() {   
    alert('inside javascript'); 
    window.open("tableOutput.php")
  };
</script>

nothing happens, even the alert does not get executed.

Please help.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I am surprised the _blank reuses the same new tab

You cannot use window.open to post to a new window/tab without a lot of code.

Try this:

let cnt = 0;
document.querySelector("[name=frmTableSelect]").addEventListener("submit", function() {
  this.target=`win${cnt++}`;
})
about 4 years ago · Juan Pablo Isaza Report

0

Change .submit to .onclick:

document.getElementById('knopka').onclick = function() { alert('inside javascript'); window.open("tableOutput.php") };
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!