spacer

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

home / experts / javascript / column90


Modal and Modeless Dialog Boxes

Developer News
Metasploit 3.2 Offers More 'Evil Deeds'
'Thank You Apple. Seriously.'
The Buzz: BlackBerry App Store Seen Next

Passing Parameters by Value and by Reference

The second argument of the functions showModalDialog() and showModelessDialog() can be of any type: scalar, array, string, object, etc. This argument can be used to pass parameters by value from the caller to the callee. Let's take a look at a simple example. Pop up a dialog box with this statement:

window.showModelessDialog('7a.html','Doc JavaScript');

The page 7a.html includes some text and the following script:

<SCRIPT LANGUAGE="JavaScript">
<!--
  alert(dialogArguments);
// -->
</SCRIPT>

The window object property dialogArguments is set to the second parameter passed by showModelessDialog(). We passed the string "Doc JavaScript", and indeed the alert box in 7a.html pops up this string. Try displaying 7a.html by itself, and you'll get an undefined parameter error (dialogArguments).

Above, we passed the parameter by value. The callee can only read the passed parameter, but cannot change it in the caller page. In order to be able to change the caller, you need to pass the parameter by reference. You do this when you pass the address of a variable. There are at least two ways to pass addresses: an array and an object. Let's demonstrate the array passing first. In this page (the caller), we define an array a as follows:

<SCRIPT LANGUAGE="JavaScript">
<!--
  var a = new Array;
  a[0]="first";
  a[1]="second";
  a[2]="third";
// -->
</SCRIPT>

And we pass the array a to the dialog box:

window.showModelessDialog('7b.html',a);

The callee 7b.html includes the following script:

<SCRIPT LANGUAGE="JavaScript">
<!--
  a = dialogArguments;
  a[0] = "fourth";
// -->
</SCRIPT>

The callee changed the first element of the array and it should be reflected in the caller page. Let's try it. First, let's make sure the array a is as we initialized it: "first,second,third". Now, call 7b.html to change it:

window.showModelessDialog('7b.html',a);

Notice how we pass the array a as the second argument of showModelessDialog(). Feel free to close the dialog box. The dialog box already modified a[0], so you should see a modified array: "fourth,second,third".

Next: How to pass objects to dialog boxes

http://www.internet.com



JupiterOnlineMedia

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

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Tripwire Whitepaper: Seven Practical Steps to Mitigate Virtualization Security Risks
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview · Controllers: Programming Application Logic - Part 2 · How to Use JavaScript to Validate Form Data
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Choosing the Right Online Backup Provider · Mother Avaya Nurtures Her Technology Partners · Software as a Service a Winning Model for Hotspot Provider


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/7.html