View Full Version : Need help accessing parent window form elements form child modal window.

07-30-2007, 02:32 PM
1) Script Title: DHTML Modal window v1.01

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/dhtmlmodal.htm

3) Describe problem: First thing, apologies for posting this in the submit DHTML script forum, click the wrong button and didn't realize it until I came back on.

I am using a modal window to modify options of a select box on the parent window. Is it possible to access form elements of the parent window from the child modal window.

I have one select box that based on a selection will populate select box 2, now if an option is not available or does not exist in select box 2 i would like to open the modal window and be able to add elements to this select box. Which this works but I can not find a way to know what the selection is for select box 1 from the modal window.

Any help appreciated. Thanks

07-30-2007, 02:53 PM
This is complicated as, the content in the model window can be either on the page that you are calling the parent or it could be on a separate page in either an iframe, or perhaps even loaded via Ajax. The easiest way would be to have it be on the page. That way, it's all one page and there is no parent/child barrier to cross.

The second easiest is if it is an iframe, then objects on the top page are known by the same identifier that they are know by on the top page with the prefix of parent. added. For example, if you have a select named 'choice1' in a form named 'choices', it would be known on the top page as:


and in the iframe as:


The hardest is with Ajax added content, it will exhibit the same ease of access as content that is already on the page, except where it comes to initializing javascript actions, then it can become very complex. I'd recommend against using it if it gives you any problems.

07-30-2007, 07:18 PM

Thank you. I am using iframe luckily and I was close just couldn't get the syntax down correctly, im a new to javascript obviously, but i missed that i needed to refer to the parent with just parent and the rest as if refering to the same window.

I am using AJAX in the child window to create a select box based on the selected index of the select box in the parent window, but I couldn't figure out how to access it. Now that I do dynamically it is working. Hopefully the rest will be easier.

Thanks again for your prompt reply.