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

247
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

Change .submit to .onclick:

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