phppup Posted July 16, 2022 Share Posted July 16, 2022 I want to have the results of a SQL query appear in a newly launched browser window. As I am aware that this is a JS function, I have managed to accomplish that portion of the task by having the processing script become the new window. action="processing.php" onclick="windowScript()" function windowScript(){ window.open("processing.php"); } but at this point, the $_POST data is NOT interacting. I suspected that this is because the PHP processing script is no longer directly receiving the submitted data. What is the best way to proceed? Quote Link to comment https://forums.phpfreaks.com/topic/315052-query-results-in-a-new-window/ Share on other sites More sharing options...
ginerjm Posted July 16, 2022 Share Posted July 16, 2022 Do you want the results to show up as their own new window while the original window is still open at the same time? Any special reason? Quote Link to comment https://forums.phpfreaks.com/topic/315052-query-results-in-a-new-window/#findComment-1598281 Share on other sites More sharing options...
kicken Posted July 16, 2022 Share Posted July 16, 2022 If you just want a new window/tab without and special properties then simply add a target attribute to your form tag. <form method="post" action="processing.php" target="_blank"> If you want to customize the popup window, add the target attribute and an onsubmit handler that open a window with the appropriate name. <form method="post" action="processing.php" target="formResults" onsubmit="openWindow()"> function openWindow(){ window.open('', 'formResults', 'width=800,height=600'); } Quote Link to comment https://forums.phpfreaks.com/topic/315052-query-results-in-a-new-window/#findComment-1598282 Share on other sites More sharing options...
phppup Posted July 16, 2022 Author Share Posted July 16, 2022 (edited) @ginerjm Quote Do you want the results to show up as their own new window while the original window is still open at the same time? Yes, absolutely. For example: a form with a drop-down of employee names that will provide data on a totally separate new window. If data for a second employee was requested, a second new window would open to provide that data. Theoretically, these windows could now be placed side by side for comparison and the main form would still be available and unchanged. Edited July 16, 2022 by phppup Forgot item Quote Link to comment https://forums.phpfreaks.com/topic/315052-query-results-in-a-new-window/#findComment-1598283 Share on other sites More sharing options...
ginerjm Posted July 16, 2022 Share Posted July 16, 2022 If you simply want a second window to open then use the target attribute as suggested by Kicken. If you want that second window to do something for you and return you to the original window's control then you need to use AJAX. Quote Link to comment https://forums.phpfreaks.com/topic/315052-query-results-in-a-new-window/#findComment-1598284 Share on other sites More sharing options...
phppup Posted July 17, 2022 Author Share Posted July 17, 2022 (edited) I'm getting closer, I suppose. Using @kicken suggestion is giving me a separate window that processes and displays the desired information. But apparently the target="xyz" forces the xyz-page to refresh with each click to submit. As I mentioned to ginerjm, Quote ....a second new window would open to provide that data. Theoretically, these windows could now be placed side by side for comparison and the main form would still be available and unchanged. so I want a new window [that would need to be physically closed by the user] with every individual click event. Edited July 17, 2022 by phppup Quote Link to comment https://forums.phpfreaks.com/topic/315052-query-results-in-a-new-window/#findComment-1598299 Share on other sites More sharing options...
ginerjm Posted July 17, 2022 Share Posted July 17, 2022 If you put out a new window with the target attribute you would have to add a button on that to close it when the user wished to. Or let the user simply close it if he remembers to. Quote Link to comment https://forums.phpfreaks.com/topic/315052-query-results-in-a-new-window/#findComment-1598301 Share on other sites More sharing options...
phppup Posted July 17, 2022 Author Share Posted July 17, 2022 I want the user to have the potential of clicking the same button a million times and having a million open windows on the screen. As it stands now, the code will TARGET one window and refresh it a million times. Please help me achieve MY goal by reading the previous posts. With all due respect, I don't need to use AJAX or add buttons to close windows. Quote Link to comment https://forums.phpfreaks.com/topic/315052-query-results-in-a-new-window/#findComment-1598304 Share on other sites More sharing options...
ginerjm Posted July 17, 2022 Share Posted July 17, 2022 (edited) Have you done any thinking on how that might be done? Using the word 'million' 3 times in your last post says to me that you are not really thinking a lot about this task you have defined. If I were doing something like this for a user to open a few windows (< 1000000) I would use a session variable. Maybe a couple of them. Edited July 17, 2022 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/315052-query-results-in-a-new-window/#findComment-1598305 Share on other sites More sharing options...
ginerjm Posted July 17, 2022 Share Posted July 17, 2022 Have you tried using a target of '_blank' instead of a named target? That should work if you don't want the starting page to be refreshed after each new window is opened. Quote Link to comment https://forums.phpfreaks.com/topic/315052-query-results-in-a-new-window/#findComment-1598307 Share on other sites More sharing options...
ginerjm Posted July 17, 2022 Share Posted July 17, 2022 (edited) OK I made a mistake in this post and have corrected my test code. If you use the blank value for the target attribute it will continue to open new windows for you IF you manage to do the click from the original window and not one of the clones. Edited July 17, 2022 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/315052-query-results-in-a-new-window/#findComment-1598308 Share on other sites More sharing options...
kicken Posted July 17, 2022 Share Posted July 17, 2022 2 hours ago, phppup said: But apparently the target="xyz" forces the xyz-page to refresh with each click to submit. As I mentioned to ginerjm, Then either use _blank, or generate a new unique target name for each submission. If you generate new unique names, remember to use the name both in the window.open call and in the forms target attribute (update it in the submission handler). Quote Link to comment https://forums.phpfreaks.com/topic/315052-query-results-in-a-new-window/#findComment-1598310 Share on other sites More sharing options...
phppup Posted July 17, 2022 Author Share Posted July 17, 2022 @kicken I guess that's the road I'll have to take. I was surprised to see that target= [which I suppose is really an HTML structure] was a solution to this problem. (I've never had occasion to use it until now) I had originally attacked this issue from a PHP perspective, but after your info, I tried many variations of _blank to resolve this. Some tests created duplicates of the form page, and others negated the new window and opened the data in a new tab (not what I wanted). I did consider the possibility of adding a count++ so that every new window has a unique name but thought I'd see if there was a more simplified option 'built-in' that I wasn't uncovering online. Thanks for your help and let me know if you have any other valuable ideas. Quote Link to comment https://forums.phpfreaks.com/topic/315052-query-results-in-a-new-window/#findComment-1598312 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.