Jump to content

Recommended Posts

I have a form  with three submit buttons that ALL have the same action="process. php"

Each submit has a different value to query a database table which provides the requested information.

Button 1 value = baseball team

Button 2 value = football team

Button 3 value = hockey team

Currently, a submission will process and provide information of the team members for the sport that is selected.

I have decided it might be nice to retrieve the data in separate windows for easy side by side comparison.

Using<form action="process. php"  onsubmit="window.open('about:blank','print_popup','width=1000,height=800');"> 

I have been able to get data to populate in a newly opened window. But the data continues to re-populate the same window.

How can I get 3 independent NEW WINDOW to open so they can be compared side by side?
 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/308653-php-in-multiple-new-windows/
Share on other sites

I'd do the data gathering via AJAX, then open the modal window using JavaScript once the AJAX response payload has been delivered. Right now you're sending the form data to process.php while trying to pop open a new window with no actual data attached.

I could well be wrong (as I said I'd just do it via AJAX and open the popup on data return), but I'm not sure you're actually doing what you think you're doing. Check the documentation: https://developer.mozilla.org/en-US/docs/Web/API/Window/open

The first parameter to the window.open() call is URL - you're passing 'about:blank' as the URL and sending your form to process.php. Two different addresses, two different actions.

I seem to be getting an acceptable result, sort of.

I believe at this point the problem is more with the "target" because I on placing results for submitting 1,2, or 3 on the same target.

If I submit with button 1, a valid result opens in a new window. If I then submit with button 2, the SAME "new window" repopulates and updates with data associated to that query.

I am currently unable to get a second "new window" to open for a side by side comparison of on screen data.

I was thinking of using JS to alter the name of the "target" so I could hopefully evade the conflict in that manner.

But not having much luck there either.

 

4 minutes ago, phppup said:

If I submit with button 1, a valid result opens in a new window. If I then submit with button 2, the SAME "new window" repopulates and updates with data associated to that query.

Read the documentation maxxd linked until you find out why it's behaving that way.

I've read the link.

It seems to indicate in the first section that leaving the windowName empty will cause new windows to be opened, yet that does not seem to be the case.

is this bc I'm using chrome at the moment (I would think not).

so what am I doing wrong?

I've read the link.

It seems to indicate in the first section that leaving the windowName empty will cause new windows to be opened, yet that does not seem to be the case.

is this bc I'm using chrome at the moment (I would think not).

so what am I doing wrong?

Or perhaps I am misunderstanding.

When the link states: 

If the string is empty, the browser will create a new window every time

are the statement meant to indicate "... Everytime that a singular new window is opened" but that once opened, it will forever be pointed to until closed?

Or does everytime meet my goal, which is to open a new window everytime a submit button is clicked???

So confused now.

 

You can do what you want by dynamically setting the form's target as you had guessed.  I've done this a few times in the past to submit a form into a popup window.

For example:

<form action="https://aoeex.com/datetime.php" target="_blank" id="theForm">
<ul>
    <li><button type="submit" name="which" value="first">First button</button></li>
    <li><button type="submit" name="which" value="second">Second button</button></li>
    <li><button type="submit" name="which" value="third">Third button</button></li>
</ul>
</form>
var $form = $('#theForm');

$form.find('button').click(function(e){
    var target = $(e.target);
    var windowName = target.val();
    window.open('', windowName, 'width=450,height=100,scrollbars,resizable');
    $form.attr('target', windowName);
});

It's not possible to detect which button submitted a form during the submit handler so you have to instead attach your event listener to each button.  In the click handler you can open your new window with an appropriate window name and then set the form's target attribute to that name.

If a popup blocker stops your window.open from functioning then your form will instead open in a new tab/full window due to the target attribute.

Thanks KICKEN.

I came up with something similar at 2:AM this morning, which uses Javascript in a shoddy kinda way, but looked as if it would get the job done.

This seems like an excellent alternative to weigh in contention, and looks as if it too, would do EXACTLY what I am attempting to accomplish.

Thanks again.

Not gonna lie, I didn't realize attaching a target attribute to a form would do anything at all...

There's obviously nothing wrong with your response kicken, but personally (just for readability if nothing else) I'd still seriously consider doing this via AJAX and opening the modal after the processing script returns the data, using a data-{whatever} attribute on the buttons to tell the processing script which logic branch to follow. I have, however, been accused of working harder than I work smart sometimes.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.