spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column90


Modal and Modeless Dialog Boxes

Developer News
HP to Microsoft: Thanks for Nothing
iPhone Remains Left Out as Android Scores Flash
The Year of Living the OpenSocial

Passing Objects back to the Caller

Let's study the dialog box definition from the previous page's example. Here is the callee:

<HTML>
<HEAD>
<TITLE>callee.html</TITLE>
<SCRIPT>

function getInfoAndUpdate() {
  var callerWindowObj = dialogArguments;
  callerWindowObj.sColor = oEnterColor.value;
  callerWindowObj.update();
}

function cancel() {
  var callerWindowObj = dialogArguments;
  callerWindowObj.sColor = "Yellow";
  callerWindowObj.update();
}
</SCRIPT>
</HEAD>
<BODY>
Enter your favorite color:<INPUT ID=oEnterColor><BR><BR>
<INPUT VALUE="Apply" TYPE=button
  onclick="getInfoAndUpdate();">
<INPUT VALUE="Ok" TYPE=button
  onclick="getInfoAndUpdate();window.close();">
<INPUT VALUE="Cancel" TYPE=button
  onclick="cancel();window.close();">
</BODY>
</HTML> 

We have one input field for the user's favorite color, oEnterColor, and three buttons: Apply, Ok, and Cancel. When either the Apply or the Ok buttons are clicked, the function getInfoAndUpdate() is called:

function getInfoAndUpdate() {
  var callerWindowObj = dialogArguments;
  callerWindowObj.sColor = oEnterColor.value;
  callerWindowObj.update();
}

We first assign dialogArguments to a local variable, callerWindowObj. Now we have the caller window object in callerWindowObj. We assign the caller's static variable, sColor, by setting it to the user's input:

 callerWindowObj.sColor = oEnterColor.value;

And then we call the caller's update function:

  callerWindowObj.update();

Notice that the function update() is defined in another file, caller.html. It's the window object that passes all caller's functions to the callee. To remind you, the update() function is defined as follows:

function update() {
  oColor.innerText = sColor;
}

When the Cancel button is clicked, a similar scenario is taking place, except that the value passed back is "Yellow" instead of the user's input:

function cancel() {
  var callerWindowObj = dialogArguments;
  callerWindowObj.sColor = "Yellow";
  callerWindowObj.update();
}

Next: A Final Word

http://www.internet.com

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

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

webref The latest from WebReference.com Browse >
Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script · Book Review: Content Rich
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Gateway Launches New Core i7-powered FX-Series Gaming PCs · Review: Lenovo ThinkPad SL300 · EBay, Alternative Site Holiday Resources for Sellers


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: August 13, 2001
Revised: August 13, 2001

URL: http://www.webreference.com/js/column90/9.html