spacer
Yehuda Shiran August 29, 2001
Modifying a Global Variable from within the Dialog Box
Tips: August 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

When you call an Internet Explorer dialog box with either showModalDialog() or showModelessDialog(), you can use the second parameter to pass information from the caller to the callee and vice versa. Suppose you have a global variable, sColor, in the caller. You want to update the sColor value from within the callee. You need to pass it by reference, but JavaScript passes scalar variables only by value. You know that all global variables are properties of the window object. You can pass the window object to the callee, modify the sColor property, and get the global variable sColor updated this way.

Let's see how we do it in code. The global variable sColor is defined in the caller as:

var sColor=""; 
You call the dialog box as follows:

showModelessDialog("010828b.html",window,
   "status:false;dialogWidth:300px;dialogHeight:150px");
Notice the window object in the second position. The callee reads in the second parameter into the dialogArguments variable. It can be a scalar, an array, an object, etc. In the following example the callee first assigns dialogArguments to the callerWindowObj, and then sets the sColor property of this object to the desired value (oEnterColor.value from the form):

  var callerWindowObj = dialogArguments;
  callerWindowObj.sColor = oEnterColor.value;
For more on modal and modeless dialog boxes, go to Column 90, Modal and Modeless Dialog Boxes.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business