Pop up to print, keeping the action values

Asked

Viewed 52 times

1

I have a form that when pressing Ubmit it takes the selected value and takes to the target page of the action and opens the page, but overlap the current page, I need to take these values of the form to the page pop up without the form open the page of the action.

  <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>

tried with

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

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

  • Passes via get in the URL, like "window.open('popup.html? var1=value', ...)

1 answer

1


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

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

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

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

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

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

form.method = "post";
  • I’m sorry, that was a misunderstanding. That pop up there is what I use in something else, what I tested was POP = window.open('folhapgt_print.php', 'thePopup', 'width=350,height=350');

  • Anyway, it just needs a few corrections... just a second

  • Inside while? <? php $data_selected = $_POST['data_selected']; ?>

  • In case you should pick up with $_GET... if you want to pick up with $_POST, have to add in function form.method = "post";

  • It worked, thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.