Can I pass a value from a form to a popup, display something based on what was submitted, and then pass something back?

I need to do this using PHP and Javascript.

I have one form with multiple inputs. One of them is the floor.

When they click on the link / button, I need to pass the value of the gender drop-down list to the popup.

Based on this value, I show portraits of men or women.

I would like to pass the value back to the parent window as soon as they selected the portrait, and then click the button.

I have code to display portaits. But how do I pass values ​​back and forth, and how do I make the value passed from the parent window available for my PHP code in a new popup?

Any help is greatly appreciated.

+3
source share
1 answer

The problem is well defined, but the question itself is still somewhat vague. I will give him a chance. If you really mean a pop-up window (separate window), and not a dialog box on a page (for example, jQuery interface elements, etc.), then the communication channel you want to use is the object returned from window.open()for communication from parent page to child page and window.openerfor communication from child to parent. For instance:

var genderPicker = document.getElementById('genderSelect');
var gender = genderPicker.options[genderPicker.selectedIndex].value;
var portraitChooserWindow = window.open("path/to/script.ext?gender=" + gender);
// portraitChooserWindow is now a reference to the newly opened pop-up (or null if the browser blocked pop-ups)

From the child window is window.openernow a link to the parent window.

+3
source

Source: https://habr.com/ru/post/1781236/


All Articles