Pop up to print, keeping the action values

1

I have a form that by pressing submit it takes the selected value and takes you to the destination page of the action and opens the page, but overlays the current page, I need to take these values from the form to the pop up page without the form opening the action page.

  <form id="form1" name="form1" method="get" action="folhapgt_imprimir.php">                
     <select name="data_selecionada" id="data">                                             
            <?php $dados = mysql_query("SELECT DISTINCT periodo FROM folha_func_sal_cc ORDER BY periodo DESC") or die(mysql_error()); 
                   while ($data = mysql_fetch_array($dados))   
                   {
                        echo "<option value='{$data['periodo']}'";  
                        if($_GET['data_selecionada'] == $data['periodo']) 
                            echo "selected='selected'";     
                            echo ">{$data['periodo']}</option>"; 
                   }
            ?>
     </select>      
     <input type="submit" name="submit" id="submit" value="OK" style="margin-left: 10px;">     
  </form>
</li>

I tried with

function pop() 
      {
        POP = window.open('folhapgt_imprimir.php', 'thePopup', 'width=350,height=350');
      }

but without success, open the page that I need but does not take the value.

    
asked by anonymous 19.04.2018 / 15:18

1 answer

1

Just use as target the name of the popup window. This way there will be no action on the current page.

Include the onclick="pop()" event that will call the function:

<input onclick="pop()" type="submit" name="submit" id="submit" value="OK" style="margin-left: 10px;">

Then include .target for the popup window name in the pop() function:

function pop(){
  var POP = window.open('folhapgt_imprimir.php', 'thePopup', 'width=350,height=350');
  var form = document.body.querySelector("#form1");
  form.target = "thePopup";
}

So the form will be sent via GET (attribute method of form ) to the open popup. If you want to send via post , add one more line in the function:

form.method = "post";
    
19.04.2018 / 17:29