Results 1 to 3 of 3

Thread: Need help accessing parent window form elements form child modal window.

  1. #1
    Join Date
    Jul 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help accessing parent window form elements form child modal window.

    1) Script Title: DHTML Modal window v1.01

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...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

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    document.forms['choices']['choice1']
    and in the iframe as:

    Code:
    parent.document.forms['choices']['choice1']
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jul 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    John,

    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.

    Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •