This topic is locked
[SOLVED]

 Pass string from popup to parent

4/20/2012 11:04:52 AM
PHPRunner General questions
W
wildwally author

I'm looking for some help or guidance with this task.
From page1_add.php I want a button that a user can click and it would then open a popup window with stringbuilder_add.php in it. stringbuilder_add.php should function just as it normally would if opened in the main window, this will allow the user to build an address string and when finished they clcik a save button which would sent the newely created address string back to a address field on the already open page1_add.php. I know it's possible - I see things like this done in online calculator systems all the time. Just not sure how one would go about doing it within PHPR. Both pages are created within PHPR.
Thanks,

Admin 4/20/2012

Not quite a PHPRunner question really but here is article for inspiration:

http://stackoverflow.com/questions/4350223/passing-data-between-a-parent-window-and-a-child-popup-window-with-jquery
In short - popup can use window.opener to access the calling page. Just make sure you open new page in popup via window.open() function.

W
wildwally author 4/20/2012



Not quite a PHPRunner question really but here is article for inspiration:

http://stackoverflow...dow-with-jquery
In short - popup can use window.opener to access the calling page. Just make sure you open new page in popup via window.open() function.


While your inspiration is somewhat helpful - it confirms that what i want to do is possible. However, it doesn't help me intergrate the coding examples into PHPR.
I'm trying to utilize standard PHPR pages with a slight amoutn of custom coding to the mix. From what I can tell the PHPR pages don't have form name's which this code needs to reference to see the field names. Example
opener.document.f1.p_name.value="Any value";
f1 = the form name and the p_name would be the text field. Everything that I have seen from PHPR and JS refers to Pageid and then the control name. Such as this example:
var ctrlUstate = Runner.getControl(pageid, 'Ustate');
Maybe I'm not going about this the proper way either. What I was attempting to do was in the button client before I entered the code to open the child window, this works great.


window.open("Test_add.php", "Test", "width=400,height=200");

return false;


and then through the use of a button on the Test_add.php page I tried using this code


opener.document.unknownformname.value_Architect_Dist_1.value="Any value";

// Close the popup

window.close();


I've tried numerous combination all with failed attemps and no errors, so I stumped.

Admin 4/20/2012

See approved answer on stackoverflow. There is no need to use or know form name. There is no need to use Javascript API either. Simply access any field or object using jQuery.

W
wildwally author 4/20/2012



See approved answer on stackoverflow. There is no need to use or know form name. There is no need to use Javascript API either. Simply access any field or object using jQuery.


lol, really??
Am I warm? Cold? I tend to agree that I can get a little hard headed at times, but this has got my head rolling. It's bad enough trying to make sure I'm getting things in the right place with the 20 different possiblities for one page, let alone throwing a second page into the mix.
Thanks, i'll keep looking/trying.

Admin 4/20/2012

It's just one line of code in fact:

window.opener.$("#" + id).val(newvalue);


here id is the id of form element, newvalue is the value you assigning.

W
wildwally author 4/20/2012



It's just one line of code in fact:

window.opener.$("#" + id).val(newvalue);


here id is the id of form element, newvalue is the value you assigning.


Once again I have been dupped by IE caching issue. I swear I tried that and a couple hundred different way, none of which was working. Even after changing it back to match it still would not work and I closed the IE window and reopened and still nothing. After trying it in FireFox it worked, and then I uploaded to demo account and it worked in IE. Now it works on my local IE version.
Thanks Sergey for putting me on the right path, I think I would have been working on that thing all weekend and still no luck with the root cause I was having.