Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 29th, 2005, 02:18 AM
Authorized User
 
Join Date: Jan 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anandham
Default Modal Dialog window Problem

hi friends, :)
I have a modal dialog window from which i need to
access a javascript function in the parent page.. is this possible..
please help me..very urgent..
thank u



Prem Anandh P.
Ambition Never comes to an End
__________________
Prem Anandh P.
Ambition Never comes to an End
 
Old January 29th, 2005, 05:41 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

When you call showModalDialog you need to pass "self", without the quotes, as the second argument. You can then access the opener with:
Code:
var opener = window.dialogArguments;
You can then access the functiuon "nyFunction with:
Code:
opener.myFunction();
If you are already using the second parameter you can package all you variables into an associative array:
In opener
Code:
var myVar1 = "Hello";
var myVar2 = "Joe";
var o = new Object();
o.var1 = myVar1;
o.var2 = myVar2;
o.opener = self;
var vRetVal = showModalDialog(<url>, o);
In modal dialog:
Code:
var o = window.dialogArguments;
var myVar1 = o.var1;
var myVar2 = o.var2;
var opener = o.opener;
--

Joe (Microsoft MVP - XML)
 
Old January 31st, 2005, 12:20 PM
Authorized User
 
Join Date: Jan 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anandham
Default

 hi joe:),
       Thanks for the reply..it worked wonders..
 i was trying for this more than past week..thanks for
 the solution..iwould like to know the advantages of this
 modal window over normal pop up windows..
 i belived that from the modal window we can't access
 any of the parent pages element..
 is it able to access particular element in the parent
 page from the modal window?? i'm a new bee to asp &
 javascript..pls bear with me ..
 thank u very much..




Prem Anandh P.
Ambition Never comes to an End
 
Old February 1st, 2005, 04:08 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Quote:
quote:Originally posted by anandham
  hi joe:),
     Thanks for the reply..it worked wonders..
i was trying for this more than past week..thanks for
the solution..iwould like to know the advantages of this
modal window over normal pop up windows..
The main advantage is that the user must dismiss the modal window before they can return to the main page. I use them a lot for look up lists, e.g. if asked to choose an employeee a select box would be too long so I present a search page wiwhich returns the employee name and number to the opener. Another advantage, which has been lost somewhat since XP SP 2, is that you have more control over the look of the window.

Quote:
quote:
i belived that from the modal window we can't access
any of the parent pages element..
is it able to access particular element in the parent
page from the modal window?? i'm a new bee to asp &
javascript..pls bear with me ..
thank u very much..
Well if your opener has a form named "frmMain" with a textbox named "txtSurname" then if you used the method shown in my second example then in the modal window you could show the contents of the surname box with:
Code:
alert(opener.forms.frmMain.elements.txtSurname.value);
--

Joe (Microsoft MVP - XML)
 
Old February 16th, 2005, 12:20 PM
Registered User
 
Join Date: Feb 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Passing the opener object to the Modal Dialog as an argument works perfectly fine. Thanks.

I want to change the values of the Opener elements from the Modal Dialog, so that when the dialog closes the opener shows the updated elements.

I tried changing the value from the modal dialog, but it had no effect on the opener.

If you can help me in this it would be really great....

 
Old February 16th, 2005, 12:37 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Can you show an example, it works fine here? Depending on what you are attempting the value may not show differently until you dismiss the modal dialog.

--

Joe (Microsoft MVP - XML)
 
Old February 16th, 2005, 05:19 PM
Registered User
 
Join Date: Feb 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Figured this out, Can return any number of variables from the Dialog through the returnvalue arg

window.returnValue = arg // can be a var or an array of vars

In the opener code,

var received = showmodaldialog(..)

Use this received var to set the values of the elements in the current page. This works....



 
Old February 16th, 2005, 06:08 PM
Registered User
 
Join Date: Feb 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Joe,

Thanks for your query, I have a doubt. Are you able to set the value in the opener and also make the opener refresh before dismissing the modal ?

Are you following a different method for returning/setting values instead of returnValue of modal dialog?

Your post on passing values to the modal dialog was very useful.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing data from modal dialog to window. ganga Javascript 1 September 26th, 2006 06:45 AM
how to return value from modal dialog ajaypsingh Javascript 2 May 16th, 2006 05:14 AM
download dialog problem in modal window jaisonkmathews Javascript 2 February 11th, 2005 08:57 AM
Modal dialog window eldanh ASP.NET 1.0 and 1.1 Basics 0 August 10th, 2004 02:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.