spacer
Yehuda Shiran August 27, 2001
Passing an Array to the Dialog Box
Tips: August 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

When passing a parameter by value to the dialog box, 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. 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('010827a.html',a);
The callee 010827a.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 010827a.html to change it:

window.showModelessDialog('010827a.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".

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, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint