views:

107

answers:

2

Hi all,

I'm currently trying to write a jQuery script which opens a modal box then (upon user entry) changes a value on the original page.

Currently I've got the script working on just the page itself (without the modal), but when I try to run the command from the modal the value on the main page doesn't change?

Does anyone know how I can solve this?

Thanks,

Tom

A: 

Make a function in the page itself (not the modal sub-page), then call opener.myMethod() in the modal sub-page.

SLaks
Hi,So would something like this work: $('#select_socnet').click(function(){ window.opener.$('#addnew').val('test'); window.close(); });Thanks
tommizzle
That should work; try it.
SLaks
A: 

If the modal dialog is using an iframe, then from within the iframe you can do either of the following (depending on whether you have nested iframes or whatnot).

window.parent.myMethod();  
top.myMethod();

And to access elements on the main page you could do this (assuming you have jquery included on the main page as well):

top.$('#myDiv').html('hello world');

Hope this helps.

Justin Swartsel